最后更新于1年前
这有帮助吗?
题目链接: https://leetcode.cn/problems/single-number
异或运算:同性无结果
func singleNumber(nums []int) int { var ans int for _, num := range nums { ans ^= num } return ans }
时间复杂度: 时间复杂度:O(n)O(n)O(n),其中 nnn 是数组长度,只需要对数组遍历一次
空间复杂度: 空间复杂度是 O(1)O(1)O(1)