Skip to content

Commit eff257b

Browse files
authored
Merge pull request #1271 from JiHyeonSu/main
[JiHyeonSu] WEEK 2 solutions
2 parents c86935f + 1f4207a commit eff257b

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

climbing-stairs/JiHyeonSu.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# 피보나치 수열
2+
# DP Bottom-up
3+
# 시간복잡도 및 공간복잡도 O(n)
4+
5+
class Solution:
6+
def climbStairs(self, n: int) -> int:
7+
if (n < 2):
8+
return n
9+
10+
dp = [0] * (n + 1)
11+
12+
dp[1] = 1
13+
dp[2] = 2
14+
15+
first, second = 1, 2
16+
17+
for i in range(3, n + 1):
18+
dp[i] = dp[i - 1] + dp[i - 2]
19+
20+
return dp[n]
21+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def productExceptSelf(self, nums: List[int]) -> List[int]:
3+
n = len(nums)
4+
answer = [1] * n
5+
6+
left = 1
7+
for i in range(n):
8+
answer[i] = left
9+
left *= nums[i]
10+
11+
right = 1
12+
for i in reversed(range(n)):
13+
answer[i] *= right
14+
right *= nums[i]
15+
16+
return answer
17+

valid-anagram/JiHyeonSu.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# 재배치하여 다른 문자를 만들 수 있는지 여부
2+
# 시간복잡도 / 공간복잡도 O(n)
3+
4+
class Solution:
5+
def isAnagram(self, s: str, t: str) -> bool:
6+
return Counter(s) == Counter(t)
7+

0 commit comments

Comments
 (0)