From bfee35a21c60e062c0033ba4e7e032b86dcadf7c Mon Sep 17 00:00:00 2001 From: TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> Date: Tue, 24 Sep 2024 04:50:56 +0900 Subject: Init --- 1_array_hashing/two_sum.py | 8 +++----- 1 file changed, 3 insertions(+), 5 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 81b7278..676c32b 100644 --- a/1_array_hashing/two_sum.py +++ b/1_array_hashing/two_sum.py @@ -11,8 +11,7 @@ Return the answer with the smaller index first. Example 1: -Input: -nums = [3,4,5,6], target = 7 +Input: nums = [3,4,5,6], target = 7 Output: [0,1] @@ -44,9 +43,8 @@ class Solution: def hashmap(self, nums: List[int], target: int) -> List[int]: hm: dict = {} for i, index in enumerate(nums): - diff = target - index - if diff in hm: - return [hm[diff], i] + if target - index in hm: + return [hm[target - index], i] hm[index] = i return [-1, -1] -- cgit v1.2.3