题目如下:
Two Sum
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
You can return the answer in any order.
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
x = 0
y = x+1
while True:
if nums[x] + nums[y] == target:
return [x,y]
break
else:
try:
print(nums[y+1])
except IndexError:
x += 1
y = x+1
else:
y += 1
按理说应该是返回一个长度为2的列表,可是submit提示Output Limit Exceeded
run code是可以的,但submit其中有两个test一直卡着过不去,请问各位这是什么原因?