File tree Expand file tree Collapse file tree 3 files changed +66
-0
lines changed Expand file tree Collapse file tree 3 files changed +66
-0
lines changed Original file line number Diff line number Diff line change 1+ # ์ ์ฒด ์๊ฐ๋ณต์ก๋ : O(n^2), ๊ณต๊ฐ๋ณต์ก๋ : O(n)
2+ class Solution :
3+ def threeSum (self , nums : list [int ]) -> list [list [int ]]:
4+ nums .sort () # ๋ด์ฅํจ์ sort()์ ์๊ฐ๋ณต์ก๋ O(nlogn)
5+ result = [] # ๊ณต๊ฐ๋ณต์ก๋ O(n)
6+ # ์๊ฐ๋ณต์ก๋ O(n)
7+ for i in range (len (nums ) - 2 ):
8+ if i > 0 and nums [i ] == nums [i - 1 ]:
9+ continue
10+ r = len (nums ) - 1
11+ l = i + 1
12+ # i๋ฅผ ๊ธฐ์ค์ผ๋ก l๊ณผ r์ ํ์ํ๋ ์๊ฐ ๋ณต์ก๋ : O(n)
13+ while l < r :
14+ if nums [i ] + nums [l ] + nums [r ] < 0 :
15+ l += 1
16+ elif nums [i ] + nums [l ] + nums [r ] > 0 :
17+ r -= 1
18+ else :
19+ result .append ([nums [i ], nums [l ], nums [r ]])
20+ while l < r and nums [l ] == nums [l + 1 ]: # ์ค๋ณต ์ ๊ฑฐ ๋ฐ๋ณต๋ฌธ, ์ด๋ฏธ ์งํ๋ ๋ฆฌ์คํธ๋ฅผ ๋ค์ ํ์ํ์ง ์์ผ๋ฏ๋ก ์๊ฐ๋ณต์ก๋๋ ์ถ๊ฐ๋์ง ์์
21+ l += 1
22+ while l < r and nums [r ] == nums [r - 1 ]:
23+ r -= 1
24+ l += 1
25+ r -= 1
26+ return result
27+
Original file line number Diff line number Diff line change 1+ # ์๊ฐ๋ณต์ก๋ : O(n), ๊ณต๊ฐ๋ณต์ก๋ : O(1)
2+
3+ class Solution :
4+ def climbStairs (self , n : int ) -> int :
5+ a = 1
6+ b = 2
7+ if (n == 1 ):
8+ return 1
9+ elif (n == 2 ):
10+ return 2
11+ for i in range (n - 2 ):
12+ c = a
13+ a = b
14+ b = c + b
15+ return (b )
16+
Original file line number Diff line number Diff line change 1+ # ์๊ฐ ๋ณต์ก๋ : O(n), ๊ณต๊ฐ ๋ณต์ก๋ : O(n)
2+ class Solution :
3+ def isAnagram (self , s : str , t : str ) -> bool :
4+ tmp = {}
5+ # tmp์ char:ํ์ ํ์์ผ๋ก ์ ์ฅ
6+ for key in s :
7+ if key in tmp :
8+ tmp [key ] += 1
9+ else :
10+ tmp [key ] = 1
11+ # t ๋ฌธ์์ด์ ๋๋ฉด์ ๋ํ๋๋ char์ ๋ํ tmp์ ํ์ ์ฐจ๊ฐ
12+ # tmp์ ์กด์ฌํ์ง ์๋ char ๋ฐ์ ์ return False
13+ for key in t :
14+ if key in tmp :
15+ tmp [key ] -= 1
16+ else :
17+ return False
18+ # tmp๋ฅผ ๋๋ฉด์ value๊ฐ์ด ๋ชจ๋ 0์ธ์ง ํ์ธ, ๋ชจ๋ 0์ผ ๊ฒฝ์ฐ s์ t๋ anagram์ด๋ค
19+ for i in tmp :
20+ if (tmp [i ] != 0 ):
21+ return False
22+ return True
23+
You canโt perform that action at this time.
0 commit comments