diff --git a/climbing-stairs/mandel-17.py b/climbing-stairs/mandel-17.py new file mode 100644 index 0000000000..2233946ad2 --- /dev/null +++ b/climbing-stairs/mandel-17.py @@ -0,0 +1,14 @@ +import collections + +class Solution: + num_dict = collections.defaultdict(int) + + def climbStairs(self, n: int) -> int: + if n <= 2: + return n + + if self.num_dict[n]: + return self.num_dict[n] + + self.num_dict[n] = self.climbStairs(n-1) + self.climbStairs(n-2) + return self.num_dict[n] diff --git a/valid-anagram/mandel-17.py b/valid-anagram/mandel-17.py new file mode 100644 index 0000000000..2233946ad2 --- /dev/null +++ b/valid-anagram/mandel-17.py @@ -0,0 +1,14 @@ +import collections + +class Solution: + num_dict = collections.defaultdict(int) + + def climbStairs(self, n: int) -> int: + if n <= 2: + return n + + if self.num_dict[n]: + return self.num_dict[n] + + self.num_dict[n] = self.climbStairs(n-1) + self.climbStairs(n-2) + return self.num_dict[n]