listnode(-1)在LeetCode问题1中处理
发布时间
阅读量:
阅读量
从今天起开始刷leetcode,在十一假期结束后之前完成全部习题,并在过程中记录下自己解决的题解。
提高一个要求, 所有的答案执行效率必须要超过 90% 的 python 答题者.
1. Two Sum.
classSolution(object):deftwoSum(self, nums, target):""":type nums: List[int]
:type target: int
:rtype: List[int]"""tmp=[]for i, j inenumerate(nums):
tmp.append((i, j))for k, item inenumerate(tmp):
l, m=itemfor o, p in tmp[k+1:]:if m + p ==target:return sorted((l, o))
runtime beats: 21.30%
优化1
classSolution(object):deftwoSum(self, nums, target):""":type nums: List[int]
:type target: int
:rtype: List[int]"""
for i, j inenumerate(nums):for k, l in enumerate(nums[i+1:]):if j + l ==t
全部评论 (0)
还没有任何评论哟~
