diff --git a/climbing-stairs/njngwn.py b/climbing-stairs/njngwn.py new file mode 100644 index 0000000000..1d2fb959cb --- /dev/null +++ b/climbing-stairs/njngwn.py @@ -0,0 +1,12 @@ +class Solution: + # dynamic programming with bottom-up + # Time Complexity: O(n) + # Space Complexity: O(1) + def climbStairs(self, n: int) -> int: + if n <= 2: return n + prev1, prev2 = 2, 1 + + for i in range(3, n+1): + prev1, prev2 = prev2 + prev1, prev1 + + return prev1 diff --git a/valid-anagram/njngwn.py b/valid-anagram/njngwn.py new file mode 100644 index 0000000000..da47ffffe5 --- /dev/null +++ b/valid-anagram/njngwn.py @@ -0,0 +1,7 @@ +from collections import Counter + +class Solution: + # Time Complexity: O(n), n: max(len(s), len(t)) + # Space Complexity: O(k), k: number of letters + def isAnagram(self, s: str, t: str) -> bool: + return Counter(s) == Counter(t)