File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution (object ):
2
+ def climbStairs (self , n ):
3
+
4
+ import math
5
+
6
+ # First attempt to this question.
7
+ # Get dividend and remainder of 2 steps & get all combinations & add one additional method for all 1 step combination
8
+ # But how to get all combinations? => permutation
9
+ # def climbStairs(self, n):
10
+ # # 2 steps
11
+ # two_steps = n // 2
12
+ # two_steps_remainder = n % 2
13
+ # total_steps = two_steps + two_steps_remainder
14
+ # total_permu = math.factorial(total_steps) // (math.factorial(two_steps) * math.factorial(two_steps_remainder))
15
+ # total_permu += 1
16
+ # return total_permu
17
+
18
+ # Second method - n = 2x+y
19
+ if n % 2 == 0 :
20
+ max = n // 2
21
+ else :
22
+ max = (n - 1 ) // 2
23
+
24
+ total_methods = 0
25
+
26
+ for i in range (0 , max + 1 ):
27
+ y = n - (2 * i )
28
+ total_steps = i + y
29
+
30
+ total_permu = math .factorial (total_steps ) // (math .factorial (i ) * math .factorial (y ))
31
+ total_methods += total_permu
32
+
33
+ return total_methods
Original file line number Diff line number Diff line change
1
+ class Solution (object ):
2
+ def isAnagram (self , s , t ):
3
+ character1 = []
4
+ character2 = []
5
+
6
+ # put characters in character1 and character2
7
+ for i in s :
8
+ character1 .append (i )
9
+ for i in t :
10
+ character2 .append (i )
11
+
12
+ # sort out the characters in alphabetical order
13
+ character1 .sort ()
14
+ character2 .sort ()
15
+
16
+ # compare each characters to see if they match (= anagram)
17
+ if character1 == character2 :
18
+ return True
19
+ else :
20
+ return False
You can’t perform that action at this time.
0 commit comments