diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2024-08-26 15:57:39 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2024-08-26 15:57:39 +0900 |
| commit | 8225172fc086650ca5d49ec96d03d3bc22077ee1 (patch) | |
| tree | 8558f31b8c2a611fec82897571d75cb32eba23d3 /1_array_hashing/two_sum.py | |
| parent | a1b80e66b43ed77c34357af31686697322421995 (diff) | |
Init
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: |
