File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ public class Solution {
2
+ /* T.C = O(1)
3
+ * S.C = O(1)
4
+ */
5
+ public int reverseBits (int n ) {
6
+ // Set the output to 0
7
+ int output = 0 ;
8
+ // Repeat 32 times
9
+ for (int i = 0 ; i < 32 ; i ++) {
10
+ // Shift the output value one space to the left to make room for the new bit
11
+ output <<= 1 ;
12
+ // '&' operation to get the rightmost bit and add it to the output
13
+ output = output | (n & 1 );
14
+ // Discard the rightmost bit of the 'n'
15
+ n = n >> 1 ;
16
+ }
17
+
18
+ return output ;
19
+
20
+ }
21
+ }
22
+
Original file line number Diff line number Diff line change
1
+ /*
2
+ * T.C: O(n) -> 배열 nums를 한 번 순회
3
+ * S.C: O(n) → 최대 n개의 요소가 저장됨
4
+ */
5
+ import java .util .HashMap ;
6
+
7
+ class Solution {
8
+ public int [] twoSum (int [] nums , int target ) {
9
+
10
+ HashMap <Integer , Integer > map = new HashMap <>();
11
+ for (int i = 0 ; i < nums .length ; i ++) {
12
+ int k = target - nums [i ];
13
+
14
+ if (map .containsKey (k )) {
15
+ return new int [] { map .get (k ), i };
16
+ }
17
+
18
+ map .put (nums [i ], i );
19
+ }
20
+ throw new IllegalArgumentException ("exception handling for java compilation" );
21
+
22
+ }
23
+ }
24
+
You can’t perform that action at this time.
0 commit comments