Iguales al siguiente en Go

This commit is contained in:
daviddoji committed 2026-05-08 17:21:46 +02:00
1 parent 3546cd699f
commit 7330e81ad2
1 file changed
+21
+21
View 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)) // []
}