#-*- coding: UTF-8 -*-
#AC源码【意外惊喜,还以为会超时】
class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
for i in xrange(len(nums)):
tmp=target-nums[i]
curList=nums[i+1:]
if curList.__contains__(tmp):
return [i,i+curList.index(tmp)+1]
else:continue
return []
sol=Solution()
print sol.twoSum([-1,-2,-3,-4,-5],-8)
相关文章
- LeetCode #001# Two Sum(js描述)
- 1. Two Sum + 15. 3 Sum + 16. 3 Sum Closest + 18. 4Sum + 167. Two Sum II - Input array is sorted + 454. 4Sum II + 653. Two Sum IV - Input is a BST
- 29. leetcode 167. Two Sum II - Input array is sorted
- 【LeetCode】Two Sum II - Input array is sorted
- LeetCode 167. Two Sum II – Input array is sorted
- (双指针 二分) leetcode 167. Two Sum II - Input array is sorted
- Java [Leetcode 167]Two Sum II - Input array is sorted
- [LeetCode&Python] Problem 371. Sum of Two Integers
- 【LeetCode】377. Combination Sum IV 解题报告(Python & C++)
- 【LeetCode】216. Combination Sum III 解题报告(Python & C++)