码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode刷题

时间:2018-12-06 23:59:00      阅读:299      评论:0      收藏:0      [点我收藏+]

标签:pre   int   leetcode   span   range   rev   sign   ret   type   

1 两数之和

#20181205
class
Solution: def twoSum(self,nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ n = len(nums) d = {} for i in range(n): a = target - nums[i] if nums[i] in d: return d[nums[i]], i else: d[a] = i

2 整数反转

#20181206
class
Solution: def reverse(self, x): """ :type x: int :rtype: int """ reverse_x = "" sign = "" if x < 0: x = -x sign = "-" for i in str(x): reverse_x = i + reverse_x reverse_x = sign + reverse_x if int(reverse_x) < pow(-2, 31) or int(reverse_x) > pow(2, 31) - 1: return 0 return int(reverse_x)

 

leetcode刷题

标签:pre   int   leetcode   span   range   rev   sign   ret   type   

原文地址:https://www.cnblogs.com/ruanshuai/p/10080373.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!