File tree Expand file tree Collapse file tree 3 files changed +54
-0
lines changed
Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments