leetcode 1 two sum
This commit is contained in:
parent
0ec24478f1
commit
2747422c40
24
leetcode/1.py
Normal file
24
leetcode/1.py
Normal file
@ -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)
|
||||||
|
"""
|
Loading…
x
Reference in New Issue
Block a user