Given a non-empty array of integers nums, every element appears twice except for one. Find that single one

前端 未结 0 1852
青春惊慌失措
青春惊慌失措 2021-02-10 14:07

nums.sort() i = 0 for i in range(len(nums)-1): if nums[i] == nums[i+1]: i = i + 2 else: return nums[i]

Could someone please explain why this code doesn\'t work? The logic

相关标签:
回答
  • 消灭零回复
提交回复
热议问题