Skip to content

Instantly share code, notes, and snippets.

@ecamellini
Created December 22, 2021 16:00
Show Gist options
  • Save ecamellini/b31b46cc488b001e1ef2da654f786970 to your computer and use it in GitHub Desktop.
Save ecamellini/b31b46cc488b001e1ef2da654f786970 to your computer and use it in GitHub Desktop.
from typing import List
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
for i in range(len(nums)):
for j in range(i+1, len(nums)):
if nums[i] + nums[j] == target:
return [i, j]
if __name__ == "__main__":
assert Solution().twoSum([2, 7, 11, 15], 9) == [0, 1]
assert Solution().twoSum([3, 7, 11, 15, 3, 7, 11], 18) == [0, 3]
assert Solution().twoSum([3, 2, 4], 6) == [1, 2]
assert Solution().twoSum([3, 3], 6) == [0, 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment