热门

最新

红包

立Flag

投票

同城

我的

发布
weixin_45835954
weixin_45835954
6 年前
trueweixin_45835954

eNSP配置无线网络

CSDN App 扫码分享
分享
评论
3
打赏
  • 复制链接
  • 举报
下一条:
两数之和给定一个整数组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)]
立即登录