Iguales al siguiente en Go
This commit is contained in:
21
src/Go/001.go
Normal file
21
src/Go/001.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func same_to_next(lst []int) []int {
|
||||
_lst := []int{}
|
||||
for i := 0; i+1 < len(lst); i++ {
|
||||
if lst[i] == lst[i+1] {
|
||||
_lst = append(_lst, lst[i])
|
||||
}
|
||||
}
|
||||
return _lst
|
||||
}
|
||||
|
||||
func main() {
|
||||
check := []int{1, 2, 2, 2, 3, 3, 4}
|
||||
fmt.Println(same_to_next(check)) // [2 2 3]
|
||||
|
||||
check = []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
|
||||
fmt.Println(same_to_next(check)) // []
|
||||
}
|
||||
Reference in New Issue
Block a user