package main
import "fmt"
func SingleNumber(numbers []int) int {
var tmp int = 0
for _, v := range numbers {
tmp ^= v
}
return tmp
}
func SingleNumberHelper(numbers []int) {
result := SingleNumber(numbers)
fmt.Printf("Find successfully, (%d) \n", result)
}
func main() {
SingleNumberHelper([]int {1, 2, 2, 3, 3})
SingleNumberHelper([]int {1, 2, 3, 3, 1})
SingleNumberHelper([]int {3, 9, 3, 9, 3})
}
运行结果为
Find successfully, (1)
Find successfully, (2)
Find successfully, (3)
网友评论