This commit is contained in:
sangge-rockpi 2024-01-19 20:29:48 +08:00
parent 2747422c40
commit 370535504e

View File

@ -6,9 +6,15 @@ class Solution:
def twoSum(self, nums: list[int], target: int) -> list[int]: def twoSum(self, nums: list[int], target: int) -> list[int]:
answer = [] answer = []
for i in range(len(nums) // 2 + 1): for i in range(len(nums) // 2 + 1):
if target - nums[i] == nums[i]: another = target - nums[i]
continue
if target - nums[i] in nums: # both number in the list
if another in nums:
if nums[i] == another:
temp_list = nums
temp_list.pop(i)
if another not in temp_list:
continue
answer.append(i) answer.append(i)
answer.append(nums.index(target - nums[i])) answer.append(nums.index(target - nums[i]))
return answer return answer