Skip to content

Instantly share code, notes, and snippets.

@tomkaith13
Created May 17, 2014 03:45
Show Gist options
  • Save tomkaith13/8a63947141fe7790b27c to your computer and use it in GitHub Desktop.
Save tomkaith13/8a63947141fe7790b27c to your computer and use it in GitHub Desktop.
leetcode - single number
'''
Given an array of integers, every element appears twice except for one. Find that single one.
'''
class Solution:
# @param A, a list of integer
# @return an integer
def singleNumber(self, A):
A.sort()
x=0
y=1
if len(A) == 1:
return A[0]
else:
for i in xrange(len(A) / 2):
#print x,y,i
if A[x] != A[y]:
return A[x]
break
x = x+2
y = y+2
else:
return A[-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment