Skip to content

Commit 1f7be88

Browse files
committed
week02_1_2_3_solution
1 parent 688c7c4 commit 1f7be88

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

climbing-stairs/YOOHYOJEONG.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# https://leetcode.com/problems/climbing-stairs
2+
3+
class Solution(object):
4+
def climbStairs(self, n):
5+
if n <= 2:
6+
return n
7+
8+
a, b = 1, 2
9+
for i in range(3, n+1):
10+
a, b = b, a+b
11+
12+
return b
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# https://leetcode.com/problems/product-of-array-except-self/
2+
3+
class Solution(object):
4+
def productExceptSelf(self, nums):
5+
6+
n = len(nums)
7+
output = [1] * n
8+
9+
left = 1
10+
for i in range(n):
11+
output[i] = left
12+
left *= nums[i]
13+
14+
right = 1
15+
for i in range(n-1, -1, -1):
16+
output[i] *= right
17+
right *= nums[i]
18+
19+
return output

valid-anagram/YOOHYOJEONG.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# https://leetcode.com/problems/valid-anagram/
2+
3+
class Solution(object):
4+
def isAnagram(self, s, t):
5+
if sorted(s) == sorted(t):
6+
return True
7+
else:
8+
return False

0 commit comments

Comments
 (0)