技巧96-100
96. 只出现一次的数字class Solution(object): def singleNumber(self, nums): x0 for num in nums: xx^num return x97. 多数元素class Solution(object): def majorityElement(self, nums): count0 candidateNone for num in nums: if count0: candidatenum count1 if candidatenum else -1 return candidate98. 颜色分类class Solution(object): def sortColors(self, nums): left,right0,len(nums)-1 cur 0 while curright: if nums[cur]2: nums[cur],nums[right]nums[right],nums[cur] right-1 elif nums[cur]0: nums[cur],nums[left]nums[left],nums[cur] cur1 left1 else: cur199. 下一个排列class Solution(object): def nextPermutation(self, nums): nlen(nums) in-2 while i0 and nums[i]nums[i1]: i-1 if i0: jn-1 while nums[j]nums[i]: j-1 nums[i],nums[j]nums[j],nums[i] left, right i 1, n - 1 while left right: nums[left], nums[right] nums[right], nums[left] left 1 right - 1100. 寻找重复数class Solution(object): def findDuplicate(self, nums): slow nums[0] fast nums[0] while True: slow nums[slow] fast nums[nums[fast]] if slow fast: break slow nums[0] while slow ! fast: slow nums[slow] fast nums[fast] return slow