Skip to content

Commit 3f4a8e2

Browse files
committed
Week 2: Change the code
1 parent 0a8e5ba commit 3f4a8e2

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

valid-anagram/mandel-17.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
import collections
2+
13
class Solution:
2-
def isAnagram(self, s: str, t: str) -> bool:
3-
def count_char(target_str):
4-
dict_char = {}
5-
for c in target_str:
6-
dict_char[c] = dict_char.get(c, 0) + 1
7-
return dict_char
4+
num_dict = collections.defaultdict(int)
85

9-
dict_s = count_char(s)
10-
dict_t = count_char(t)
6+
def climbStairs(self, n: int) -> int:
7+
if n <= 2:
8+
return n
119

12-
if dict_s == dict_t:
13-
return True
14-
return False
10+
if self.num_dict[n]:
11+
return self.num_dict[n]
1512

13+
self.num_dict[n] = self.climbStairs(n-1) + self.climbStairs(n-2)
14+
return self.num_dict[n]

0 commit comments

Comments
 (0)