1 (1_twosum)
标准答案1
class Solution(object):
def twoSum(self, nums, target):
dic = {}
for i, num in enumerate(nums):
if num in dic:
return [dic[num], i]
else:
dic[target - num] = i
2 (7_ReverseInteger)
自己的答案:注意有个超出范围溢出!
class Solution(object):
def reverse(self, x):
if '-' not in str(x):
x = [int(i) for i in list(str(x))]
x = x[::-1]
x = [str(i) for i in x]
x = ''.join(x)
x = int(x)
else:
x = str(x).strip('-')
x = [int(i) for i in list((x))]
x = x[::-1