热门

最新

红包

立Flag

投票

同城

我的

发布
m0_53598210
李水水.
6 年前
truem0_53598210

两数之和
给定一个整数组nums,和一个目标值target,请你在该数组中找出和为目标值的两个整数,并返回他们的数组下标。
你可以假设每种输入只会对应一个答案,但是数组中同一个元素不能使用两边。
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
i = 0
length = len(nums)
result_index = -1
result = 0
while i < length - 1:
result = target - nums[i]
try:
result_index = nums[i+1:].index(result)
except:
i += 0
return [i,nums.index(result,i+1)]

CSDN App 扫码分享
分享
3
4
打赏
  • 复制链接
  • 举报
下一条:
有没有大佬提供一个安全的冰河控制,网上都是捆绑后门
立即登录