Skip to content

Commit d982476

Browse files
authored
Merge pull request #737 from EstherKim97/main
[EstherKim97] WEEK 02
2 parents fb00558 + 594b023 commit d982476

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

climbing-stairs/EstherKim97.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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

valid-anagram/EstherKim97.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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

0 commit comments

Comments
 (0)