-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
51 lines (46 loc) · 647 Bytes
/
main.go
File metadata and controls
51 lines (46 loc) · 647 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"log"
)
/*
*
*
* This func for remove custom
* Value from slice
*
* args:
* nums []int slice
* val int
*
* return:
* int
*
*
*/
func removeElement(nums []int, val int) int {
// counter for length
// slice without val number
var i int = 0
for _, n := range nums {
// check if n != vla
// last index (i)
// get value n
// and i = i + 1
if n != val {
nums[i] = n
i++
}
}
return i
}
func main() {
// very simple test
nums := []int{1, 1, 1}
ans := []int{}
for i := 0; i < removeElement(nums, 1); i++ {
if ans[i] != nums[i] {
log.Fatal("Wrong Answer!")
}
}
log.Println("True Answer!")
}