Skip to content

Instantly share code, notes, and snippets.

@yokolet
Created October 17, 2018 18:59
Show Gist options
  • Select an option

  • Save yokolet/ddaadd36d93de7311985041c1acf3f1b to your computer and use it in GitHub Desktop.

Select an option

Save yokolet/ddaadd36d93de7311985041c1acf3f1b to your computer and use it in GitHub Desktop.
Single Number
"""
Description:
Given a non-empty array of integers, every element appears twice except for one. Find
that single one. The algorithm should have a linear runtime complexity.
Examples:
Input: [2,2,1]
Output: 1
Input: [4,1,2,1,2]
Output: 4
"""
def singleNumber(nums):
"""
:type nums: List[int]
:rtype: int
"""
v = 0
for num in nums:
v ^= num
return v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment