diff --git a/climbing-stairs/daehyun99.py b/climbing-stairs/daehyun99.py new file mode 100644 index 0000000000..09681c6150 --- /dev/null +++ b/climbing-stairs/daehyun99.py @@ -0,0 +1,20 @@ +class Solution: + def climbStairs(self, n: int) -> int: + one_count = n + two_count = 0 + total_count = 0 + + while one_count >=0 and two_count >=0: + # 조합 + total = one_count + two_count + + count = 1 + for i in range(two_count): + count *= total - i + for i in range(two_count, 0, -1): + count /= i + total_count += count + + one_count -=2 + two_count +=1 + return int(total_count) diff --git a/product-of-array-except-self/daehyun99.py b/product-of-array-except-self/daehyun99.py new file mode 100644 index 0000000000..26e3fee3e2 --- /dev/null +++ b/product-of-array-except-self/daehyun99.py @@ -0,0 +1,18 @@ +class Solution: + def productExceptSelf(self, nums: List[int]) -> List[int]: + product = 1 + zero_pos = set() + + for i in range(len(nums)): + num = nums[i] + if num != 0: + product *= num + else: + zero_pos.add(i) + + if len(zero_pos) >= 2: + return [0 for num in nums] + elif len(zero_pos) == 1: + return [0 if i not in zero_pos else product for i in range(len(nums))] + else: + return [int(product / num) for num in nums] diff --git a/valid-anagram/daehyun99.py b/valid-anagram/daehyun99.py new file mode 100644 index 0000000000..bfcc871ed1 --- /dev/null +++ b/valid-anagram/daehyun99.py @@ -0,0 +1,16 @@ +from collections import defaultdict +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + count = defaultdict(int) + + if len(s) != len(t): + return False + + for s_, t_ in zip(s, t): + count[s_] += 1 + count[t_] -= 1 + + for key, val in count.items(): + if val != 0: + return False + return True