leecode

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 :

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值