Created
December 22, 2021 16:00
-
-
Save ecamellini/b31b46cc488b001e1ef2da654f786970 to your computer and use it in GitHub Desktop.
Solution to: https://leetcode.com/problems/two-sum/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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