From 8ce8f25f3bd1f96ae1a8059bdcbb29c13aa94716 Mon Sep 17 00:00:00 2001 From: Esther <181283957+EstherKim97@users.noreply.github.com> Date: Tue, 17 Dec 2024 20:59:09 -0800 Subject: [PATCH 1/4] Anagram --- valid-anagram/EstherKim97.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 valid-anagram/EstherKim97.py diff --git a/valid-anagram/EstherKim97.py b/valid-anagram/EstherKim97.py new file mode 100644 index 000000000..aea026b70 --- /dev/null +++ b/valid-anagram/EstherKim97.py @@ -0,0 +1,20 @@ +class Solution(object): + def isAnagram(self, s, t): + character1 = [] + character2 = [] + + # put characters in character1 and character2 + for i in s: + character1.append(i) + for i in t: + character2.append(i) + + # sort out the characters in alphabetical order + character1.sort() + character2.sort() + + # compare each characters to see if they match (= anagram) + if character1 == character2: + return True + else: + return False From fc94ed7e5a0be5693b6d78bf1101223f903da00e Mon Sep 17 00:00:00 2001 From: Esther <181283957+EstherKim97@users.noreply.github.com> Date: Wed, 18 Dec 2024 00:51:13 -0800 Subject: [PATCH 2/4] code for climbing stairs --- climbing-stairs/EstherKim97.py | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 climbing-stairs/EstherKim97.py diff --git a/climbing-stairs/EstherKim97.py b/climbing-stairs/EstherKim97.py new file mode 100644 index 000000000..54c59edf8 --- /dev/null +++ b/climbing-stairs/EstherKim97.py @@ -0,0 +1,37 @@ +class Solution(object): + def climbStairs(self, n): + + import math + + # Second method - n = 2x+y + if n % 2 == 0: + max = n //2 + else: + max = (n-1) // 2 + + total_methods = 0 + + for i in range(0, max+1): + y = n - (2 * i) + total_steps = i + y + + total_permu = math.factorial(total_steps) // (math.factorial(i) * math.factorial(y)) + total_methods += total_permu + + return total_methods + + + # First attempt to this question. + # Get dividend and remainder of 2 steps & get all combinations & add one additional method for all 1 step combination + # But how to get all combinations? => permutation + # def climbStairs(self, n): + # # 2 steps + # two_steps = n // 2 + # two_steps_remainder = n % 2 + + # total_steps = two_steps + two_steps_remainder + + # total_permu = math.factorial(total_steps) // (math.factorial(two_steps) * math.factorial(two_steps_remainder)) + # total_permu += 1 + + # return total_permu \ No newline at end of file From 1761b4f619102ece5bb30c43e6bbb51d05bd236e Mon Sep 17 00:00:00 2001 From: Esther <181283957+EstherKim97@users.noreply.github.com> Date: Wed, 18 Dec 2024 00:52:22 -0800 Subject: [PATCH 3/4] error --- climbing-stairs/EstherKim97.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/climbing-stairs/EstherKim97.py b/climbing-stairs/EstherKim97.py index 54c59edf8..db0d5ae71 100644 --- a/climbing-stairs/EstherKim97.py +++ b/climbing-stairs/EstherKim97.py @@ -34,4 +34,5 @@ def climbStairs(self, n): # total_permu = math.factorial(total_steps) // (math.factorial(two_steps) * math.factorial(two_steps_remainder)) # total_permu += 1 - # return total_permu \ No newline at end of file + # return total_permu + \ No newline at end of file From 594b023427ff5987cb6620d9e4910913b43699f1 Mon Sep 17 00:00:00 2001 From: Esther <181283957+EstherKim97@users.noreply.github.com> Date: Wed, 18 Dec 2024 10:33:33 -0800 Subject: [PATCH 4/4] update --- climbing-stairs/EstherKim97.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/climbing-stairs/EstherKim97.py b/climbing-stairs/EstherKim97.py index db0d5ae71..d34ce7587 100644 --- a/climbing-stairs/EstherKim97.py +++ b/climbing-stairs/EstherKim97.py @@ -3,6 +3,18 @@ def climbStairs(self, n): import math + # First attempt to this question. + # Get dividend and remainder of 2 steps & get all combinations & add one additional method for all 1 step combination + # But how to get all combinations? => permutation + # def climbStairs(self, n): + # # 2 steps + # two_steps = n // 2 + # two_steps_remainder = n % 2 + # total_steps = two_steps + two_steps_remainder + # total_permu = math.factorial(total_steps) // (math.factorial(two_steps) * math.factorial(two_steps_remainder)) + # total_permu += 1 + # return total_permu + # Second method - n = 2x+y if n % 2 == 0: max = n //2 @@ -19,20 +31,3 @@ def climbStairs(self, n): total_methods += total_permu return total_methods - - - # First attempt to this question. - # Get dividend and remainder of 2 steps & get all combinations & add one additional method for all 1 step combination - # But how to get all combinations? => permutation - # def climbStairs(self, n): - # # 2 steps - # two_steps = n // 2 - # two_steps_remainder = n % 2 - - # total_steps = two_steps + two_steps_remainder - - # total_permu = math.factorial(total_steps) // (math.factorial(two_steps) * math.factorial(two_steps_remainder)) - # total_permu += 1 - - # return total_permu - \ No newline at end of file