diff --git a/climbing-stairs/JiHyeonSu.py b/climbing-stairs/JiHyeonSu.py new file mode 100644 index 000000000..c16c4fdb3 --- /dev/null +++ b/climbing-stairs/JiHyeonSu.py @@ -0,0 +1,21 @@ +# 피보나치 수열 +# DP Bottom-up +# 시간복잡도 및 공간복잡도 O(n) + +class Solution: + def climbStairs(self, n: int) -> int: + if (n < 2): + return n + + dp = [0] * (n + 1) + + dp[1] = 1 + dp[2] = 2 + + first, second = 1, 2 + + for i in range(3, n + 1): + dp[i] = dp[i - 1] + dp[i - 2] + + return dp[n] + diff --git a/product-of-array-except-self/JiHyeonSu.py b/product-of-array-except-self/JiHyeonSu.py new file mode 100644 index 000000000..10dfc3955 --- /dev/null +++ b/product-of-array-except-self/JiHyeonSu.py @@ -0,0 +1,17 @@ +class Solution: + def productExceptSelf(self, nums: List[int]) -> List[int]: + n = len(nums) + answer = [1] * n + + left = 1 + for i in range(n): + answer[i] = left + left *= nums[i] + + right = 1 + for i in reversed(range(n)): + answer[i] *= right + right *= nums[i] + + return answer + diff --git a/valid-anagram/JiHyeonSu.py b/valid-anagram/JiHyeonSu.py new file mode 100644 index 000000000..478db78fb --- /dev/null +++ b/valid-anagram/JiHyeonSu.py @@ -0,0 +1,7 @@ +# 재배치하여 다른 문자를 만들 수 있는지 여부 +# 시간복잡도 / 공간복잡도 O(n) + +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + return Counter(s) == Counter(t) +