diff --git a/climbing-stairs/deepInTheWoodz.py b/climbing-stairs/deepInTheWoodz.py new file mode 100644 index 0000000000..0eeb99758a --- /dev/null +++ b/climbing-stairs/deepInTheWoodz.py @@ -0,0 +1,12 @@ +# TC: O(1) +# SC: O(1) +class Solution: + def climbStairs(self, n: int) -> int: + dp = [0] * (n+2) + dp[1] = 1 + dp[2] = 2 + + for i in range(3, n+2): + dp[i] = dp[i-1] + dp[i-2] + + return dp[n] diff --git a/valid-anagram/deepInTheWoodz.py b/valid-anagram/deepInTheWoodz.py new file mode 100644 index 0000000000..10a1f4fa3c --- /dev/null +++ b/valid-anagram/deepInTheWoodz.py @@ -0,0 +1,29 @@ +# TC: O(n) +# SC: O(1) +def isAnagram(s: str, t: str) -> bool: + # TC: O(nlogn) + # SC: O(n) + # if sorted(list(s)) == sorted(list(t)): + # return True + # else: + # return False + + chars = dict() + + if len(s) != len(t): + return False + + for c in s: + chars[c] = chars.get(c, 0) + 1 + + for c in t: + if c not in chars: + return False + chars[c] -= 1 + if chars[c] == 0: + chars.pop(c) + + return True + +if __name__ == '__main__': + print(isAnagram('ab', 'a'))