def singleNumber(nums):
nums.sort()
i = 0
while i < len(nums) - 1:
if (nums[i] != nums[i + 1]):
return nums[i]
i += 2
if i >= len(nums) - 1:
return nums[-1]
def plusOne(nums):
l = len(nums)
i = 0;
while nums[l - 1 -i] + 1 == 10:
nums[l -1 -i] = 0
if (i == l - 1):
nums.insert(0, 0)
break
i += 1
nums[l - 1 -i] += 1
return nums
def movZeroes(nums):
length = len(nums)
i = 0
count = 0
while i < length:
if nums[i] == 0:
count += 1
for j in range(i, length - 1):
mid = nums[j + 1]
nums[j + 1] = nums[j]
nums[j] = mid
i -= 1
if (i == length - count -1 ):
break
i += 1
def twoSum(nums, target):
for i in range(len(nums)):
for j in range(i + 1, len(nums)):
if ( nums[i] + nums[j] == target):
return [i, j]
return
def reverse(x):
flag = 0
if x >= 0:
s = str(x)
elif x < 0:
s = str(x * (-1))
flag = 1
result = s[::-1]
if result[0] == 0:
del result[0]
x = int(result)
if (flag ==1):
x = x * (-1)
if x < 2**31 * (-1) and x >= 2**31:
return x
else:
return 0
def findFirstUniqChar(s):
if (len(s) == 2):
if s[0] != s[1]:
return 0
else:
return -1
a = []
for i in range(len(s)):
if s[i] not in s[i+1:] and s[i] not in a:
return i
a.append(s[i])
return -1
def isPalindrome(s):
mid = s.lower()
S = [ x for x in mid if 'a' <= x <= 'z' or '0' <= x <= '9' or 'A' <= x <= 'Z']
print(S)
for i in range(int(len(S) / 2)):
if S[i] != S[len(S) - 1 - i] :
return False
return True
def myAtoi(str):
# a = [x for x in str if '0' =< x <= '9']
i = 0
tmp = str.lstrip()
if len(tmp) == 0:
return 0
a = []
flag = 1
if tmp[0] == '-':
flag = -1
tmp = tmp[1:]
for x in tmp[:]:
if '0' <= x <= '9':
a.append(x)
else:
break
res = 0
print(a)
if len(a) > 0:
for x in a:
res = res * 10 +int(x)
res = res * flag
if (-1) * 2 ** 31 =< res <= 2**31 -1
return res
elif res < (-1) * 2**31:
return (-1)*2**31
elif res > 2**31 -1:
return 2**31 -1
else :