#-*- 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】304. Range Sum Query 2D - Immutable 解题报告(Python)
- LeetCode题解——Two Sum
- 【LeetCode】437. Path Sum III 解题报告(Python)
- leetcode Combination Sum II python
- Array + two points leetcode.16 - 3Sum Closest
- 【Leetcode 167】Two Sum II - Input array is sorted
- 【leetcode74】Sum of Two Integers(不用+,-求两数之和)
- ✡ leetcode 170. Two Sum III - Data structure design 设计two sum模式 --------- java
- 1.两数之和(Two Sum) C++
- leetcode刷题1:两数之和two_sum