Skip to content

Commit 5083579

Browse files
committed
re-solve "1. Two Sum"
1 parent 74326b7 commit 5083579

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

.plan

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Sep 7, 2024
2+
3+
* re-solve "1. Two Sum"
4+
15
Sep 6, 2024
26

37
* re-solve "49. Group Anagrams"

src/two_sum.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
class Solution:
22
def twoSum(self, nums: list[int], target: int) -> list[int]:
3-
seen: dict[int, int] = {}
3+
compliments: dict[int, int] = {}
44

55
for i, x in enumerate(nums):
66
compliment = target - x
7-
if compliment in seen:
8-
return [seen[compliment], i]
9-
seen[x] = i
7+
if compliment in compliments:
8+
return [compliments[compliment], i]
9+
compliments[x] = i
1010

11-
raise ValueError
11+
raise ValueError("solution not found")

0 commit comments

Comments
 (0)