File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def reverseBits (self , n : int ) -> int :
3
+ # TC : O(32)
4
+ # SC : O(32)
5
+
6
+ bit_str = '' .join (reversed (format (n , 'b' ).zfill (32 )))
7
+ return int (bit_str , 2 )
8
+
9
+
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def twoSum (self , nums : List [int ], target : int ) -> List [int ]:
3
+ """
4
+ O(n^2) 보다 빠르게 풀기 위한 방법 : 정렬 후 투포인터 이용
5
+ Tc : O(nlogn)
6
+ Sc : O(n) // queue 생성
7
+ """
8
+ n = len (nums )
9
+ queue = []
10
+
11
+ for i in range (n ):
12
+ queue .append ([nums [i ], i ])
13
+
14
+ queue .sort ()
15
+
16
+ start , end = 0 , n - 1
17
+ sum_ = queue [start ][0 ] + queue [end ][0 ]
18
+
19
+ while sum_ != target :
20
+ if sum_ > target :
21
+ end -= 1
22
+ else :
23
+ start += 1
24
+ sum_ = queue [start ][0 ] + queue [end ][0 ]
25
+
26
+ return [queue [start ][1 ], queue [end ][1 ]]
27
+
You can’t perform that action at this time.
0 commit comments