From 2747422c406011422426415b2657f3d5dd9e2c4d Mon Sep 17 00:00:00 2001 From: sangge-rockpi <2251250136@qq.com> Date: Fri, 19 Jan 2024 20:16:26 +0800 Subject: [PATCH] leetcode 1 two sum --- leetcode/1.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 leetcode/1.py diff --git a/leetcode/1.py b/leetcode/1.py new file mode 100644 index 0000000..d96e79e --- /dev/null +++ b/leetcode/1.py @@ -0,0 +1,24 @@ +# Give a list and a number. +# Return a list of indices of two numbers + + +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: + answer.append(i) + answer.append(nums.index(target - nums[i])) + return answer + + return answer + + +""" +test = [1, 2, 3] +TARGET_NUMBER = 3 +a = Solution().twoSum(test, TARGET_NUMBER) +print(a) +"""