Skip to content

Commit 43cb051

Browse files
committed
add week 3 solution
1 parent e0d7d23 commit 43cb051

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

3sum/rivkode.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from typing import List
2+
3+
# use hashtable
4+
5+
class Solution:
6+
def threeSum(self, nums: List[int]) -> List[List[int]]:
7+
result = []
8+
return result

climbing-stairs/rivkode.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Time Complexity O(n)
2+
# - traversing for loop takes O(n)
3+
# Space Complexity O(n)
4+
# - appending for loop it takes O(n)
5+
6+
class Solution:
7+
def climbStairs(self, n: int) -> int:
8+
stage = [1, 2, 3]
9+
10+
for i in range(3, 45):
11+
value = stage[i - 1] + stage[i - 2]
12+
stage.append(value)
13+
14+
return stage[n - 1]
15+
16+
if __name__ == "__main__":
17+
solution = Solution()
18+
result = solution.climbStairs(5)
19+
print(result)
20+

valid-anagram/rivkode.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from typing import List
2+
3+
# Time Complexity O(n log n)
4+
# - when sorting by sorted function(TimSort) for each string it takes O(nlogn)
5+
# - traversing for loop takes O(n)
6+
# Space Complexity O(n)
7+
# - when sorting takes O(n)
8+
9+
class Solution:
10+
def isAnagram(self, s: str, t: str) -> bool:
11+
s_sorted = sorted(s)
12+
t_sorted = sorted(t)
13+
14+
for i in range(len(s_sorted)):
15+
if s_sorted[i] != t_sorted[i]:
16+
return False
17+
return True
18+
19+
if __name__ == "__main__":
20+
solution = Solution()
21+
22+
s = "nagaram"
23+
t = "anagram"
24+
25+
result = solution.isAnagram(s, t)
26+
print(result)

0 commit comments

Comments
 (0)