恩, 沙比提
1 class Solution(object):
2 def singleNonDuplicate(self, nums):
3 """
4 :type nums: List[int]
5 :rtype: int
6 """
7 xorsum =
0
8 for i
in nums:
9 xorsum = xorsum ^
i
10 return xorsum
11
发现要logn时间, 唔, 那就是二分咯
如果mid左右和mid相等的数的下标为 "奇偶", 那就表示single在右边
相反, 如果下标为 "偶奇", 那就表示single在左边
直到mid左右没有相等的数, 就是答案
不写了
转载于:https://www.cnblogs.com/hexsix/p/6661652.html
相关资源:JAVA上百实例源码以及开源项目