From 8225172fc086650ca5d49ec96d03d3bc22077ee1 Mon Sep 17 00:00:00 2001 From: TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> Date: Mon, 26 Aug 2024 15:57:39 +0900 Subject: Init --- 1_array_hashing/two_sum.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to '1_array_hashing/two_sum.py') 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: -- cgit v1.2.3