Skip to content

Commit 32d3a22

Browse files
authored
Merge pull request DaleStudy#752 from jinah92/main
[jinah92] Week 2
2 parents fe2a645 + 969b9fb commit 32d3a22

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

3sum/jinah92.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# 공간복잡도 : O(1), 시간복잡도 : O(N^2)
2+
class Solution:
3+
def threeSum(self, nums: List[int]) -> List[List[int]]:
4+
three_sums = set()
5+
nums.sort()
6+
7+
for i in range(len(nums)-2):
8+
low, high = i + 1, len(nums)-1
9+
while low < high:
10+
three_sum = nums[i] + nums[high] + nums[low]
11+
if three_sum < 0:
12+
low += 1
13+
elif three_sum > 0:
14+
high -= 1
15+
else:
16+
three_sums.add((nums[i], nums[high], nums[low]))
17+
low, high = low+1, high-1
18+
19+
return list(three_sums)
20+

climbing-stairs/jinah92.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# 공간복잡도: O(1), 시간복잡도: O(n)
2+
class Solution:
3+
def climbStairs(self, n: int) -> int:
4+
if n < 3:
5+
return n
6+
7+
prev, curr = 1, 2
8+
for num in range(3, n+1):
9+
prev, curr = curr, prev + curr
10+
11+
return curr

valid-anagram/jinah92.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# 공간복잡도: O(n), 시간복잡도: O(n)
2+
class Solution:
3+
def isAnagram(self, s: str, t: str) -> bool:
4+
char_set_1, char_set_2 = {}, {}
5+
6+
for ch in s:
7+
char_set_1[ch] = 0 if ch not in char_set_1 else char_set_1[ch] + 1
8+
9+
for ch in t:
10+
char_set_2[ch] = 0 if ch not in char_set_2 else char_set_2[ch] + 1
11+
12+
# dictionary의 모든 요소 종류와 개수가 일치해야 함
13+
return char_set_1 == char_set_2
14+

0 commit comments

Comments
 (0)