Skip to content

Instantly share code, notes, and snippets.

@Robotboy93
Created September 11, 2022 12:11
Show Gist options
  • Save Robotboy93/afd7341d43a3dff4056e242100fc7af3 to your computer and use it in GitHub Desktop.
Save Robotboy93/afd7341d43a3dff4056e242100fc7af3 to your computer and use it in GitHub Desktop.
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any orde
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
a= b = 0
for i in range(len(nums)):
c = nums[i]
del nums[i]
if (target-c) in nums:
a = i
b = (nums.index((target-c)))
nums.insert(i,c)
result = [b,a]
return result
pass
ret = Solution().twoSum([1,2,3,4,5,6,7],8)
print(ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment