From baab69d5a647b241d7bd86da65b03f6a0fd130b3 Mon Sep 17 00:00:00 2001 From: sangge-rockpi <2251250136@qq.com> Date: Fri, 19 Jan 2024 20:52:37 +0800 Subject: [PATCH] update 1 --- leetcode/1.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/leetcode/1.py b/leetcode/1.py index f3865de..f8bf37a 100644 --- a/leetcode/1.py +++ b/leetcode/1.py @@ -11,23 +11,26 @@ class Solution: # both number in the list if another in nums: if nums[i] == another: - temp_list = nums + temp_list = nums.copy() temp_list.pop(i) if another in temp_list: answer.append(i) answer.append(temp_list.index(another) + 1) - elif another not in temp_list: + return answer + + if another not in temp_list: continue answer.append(i) answer.append(nums.index(another)) + print(nums) + print(another) + print(nums.index(another)) return answer return answer -""" -test = [1, 2, 3] -TARGET_NUMBER = 3 +test = [3, 2, 4] +TARGET_NUMBER = 6 a = Solution().twoSum(test, TARGET_NUMBER) print(a) -"""