Skip to content

Commit 9028c5c

Browse files
committed
two-sum and valid-anagram
1 parent 7db46d5 commit 9028c5c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

two-sum/Bumsu-Yi.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
"""
22
https://leetcode.com/problems/two-sum/
33
"""
4-
#
54

5+
6+
class Solution:
7+
def twoSum(self, nums: List[int], target: int) -> List[int]:
8+
numMap = {}
9+
10+
for i in range(len(nums)):
11+
complement = target - nums[i]
12+
if complement in numMap:
13+
return [numMap[complement], i]
14+
15+
numMap[nums[i]] = i

valid-anagram/Bumsu-Yi.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
"""
22
https://leetcode.com/problems/valid-anagram/
33
"""
4+
5+
6+
class Solution:
7+
def isAnagram(self, s: str, t: str) -> bool:
8+
my_dict1 = {}
9+
my_dict2 = {}
10+
11+
for char in s:
12+
my_dict1[char] = my_dict1.get(char, 0) + 1
13+
14+
for char in t:
15+
my_dict2[char] = my_dict2.get(char, 0) + 1
16+
17+
return my_dict1 == my_dict2

0 commit comments

Comments
 (0)