Skip to content

Commit f0f6b73

Browse files
authored
Merge pull request #1 from Bumsu-Yi/main
sam_lee problem1,2,3
2 parents 0b1d1b7 + 786a470 commit f0f6b73

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

sam_lee/Contains_Duplicate.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def containsDuplicate(self, nums: List[int]) -> bool:
3+
my_dict = {}
4+
5+
for num in nums:
6+
if num in my_dict:
7+
return True
8+
my_dict[num] = 0
9+
10+
return False

sam_lee/Two_Sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def twoSum(self, nums: List[int], target: int) -> List[int]:
3+
my_dict = {}
4+
5+
for i in range(len(nums)):
6+
complement = target - nums[i]
7+
if complement in my_dict:
8+
return [my_dict[complement], i]
9+
10+
my_dict[nums[i]] = i

sam_lee/Valid_Anagram

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time Complexity : O(nlog(n))
2+
# Space Complexity : 0(1)
3+
class Solution:
4+
def isAnagram(self, s: str, t: str) -> bool:
5+
return sorted(s) == sorted(t)
6+
7+
class Solution:
8+
def isAnagram(self, s: str, t: str) -> bool:
9+
my_dict1 = {}
10+
my_dict2 = {}
11+
12+
for char in s:
13+
my_dict1[char] = my_dict1.get(char, 0) + 1
14+
15+
for char in t:
16+
my_dict2[char] = my_dict2.get(char, 0) + 1
17+
18+
return my_dict1 == my_dict2

0 commit comments

Comments
 (0)