mirror of
https://github.com/teivah/100-go-mistakes.git
synced 2026-06-20 16:45:56 +08:00
23 lines
295 B
Go
23 lines
295 B
Go
package main
|
|
|
|
type node struct {
|
|
value int64
|
|
next *node
|
|
}
|
|
|
|
func linkedList(n *node) int64 {
|
|
var total int64
|
|
for n != nil {
|
|
total += n.value
|
|
n = n.next
|
|
}
|
|
return total
|
|
}
|
|
|
|
func sum2(s []int64) int64 {
|
|
var total int64
|
|
for i := 0; i < len(s); i += 2 {
|
|
total += s[i]
|
|
}
|
|
return total
|
|
}
|