diff options
Diffstat (limited to '1_array_hashing/two_sum.py')
| -rw-r--r-- | 1_array_hashing/two_sum.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/1_array_hashing/two_sum.py b/1_array_hashing/two_sum.py index 534ec87..81b7278 100644 --- a/1_array_hashing/two_sum.py +++ b/1_array_hashing/two_sum.py @@ -42,12 +42,12 @@ from typing import List class Solution: def hashmap(self, nums: List[int], target: int) -> List[int]: - mp = {} - for i, n in enumerate(nums): - diff = target - n - if diff in mp: - return [mp[diff], i] - mp[nums[i]] = i + hm: dict = {} + for i, index in enumerate(nums): + diff = target - index + if diff in hm: + return [hm[diff], i] + hm[index] = i return [-1, -1] @@ -71,8 +71,8 @@ url: https://neetcode.io/problems/two-integer-sum video: https://youtu.be/KLlXCFG5TnA 1. hashmap -time: -space: +time: O(n) +space: O(n) code: ```python class Solution: |
