diff --git a/leetcode/1.py b/leetcode/1.py index d96e79e..8a3bda2 100644 --- a/leetcode/1.py +++ b/leetcode/1.py @@ -6,9 +6,15 @@ class Solution: def twoSum(self, nums: list[int], target: int) -> list[int]: answer = [] for i in range(len(nums) // 2 + 1): - if target - nums[i] == nums[i]: - continue - if target - nums[i] in nums: + another = target - nums[i] + + # 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(nums.index(target - nums[i])) return answer