Skip to content

Commit d187b01

Browse files
authored
Merge pull request #2265 from juhui-jeong/main
[juhui-jeong] WEEK 09 solutions
2 parents 1c99505 + b254fbf commit d187b01

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* ์‹œ๊ฐ„ ๋ณต์žก๋„: O(n)
3+
* ๊ณต๊ฐ„ ๋ณต์žก๋„: O(n)
4+
*/
5+
public class Solution {
6+
public boolean hasCycle(ListNode head) {
7+
Set<ListNode> visited = new HashSet<>();
8+
while (head != null) {
9+
if (visited.contains(head)) {
10+
return true;
11+
}
12+
visited.add(head);
13+
head = head.next;
14+
}
15+
return false;
16+
}
17+
}

โ€Žreverse-bits/juhui-jeong.javaโ€Ž

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@
33
* ๊ณต๊ฐ„ ๋ณต์žก๋„: O(1)
44
*/
55
class Solution {
6+
public int reverseBits(int n) {
7+
int result = 0;
8+
9+
for (int i = 0; i < 32; i++) {
10+
result = (result << 1) | (n & 1);
11+
n >>= 1;
12+
}
13+
return result;
14+
}
15+
}
16+
17+
/*
18+
* ์‹œ๊ฐ„ ๋ณต์žก๋„: O(1)
19+
* ๊ณต๊ฐ„ ๋ณต์žก๋„: O(32)
20+
*
21+
* ํ•ด๋‹น ์ฝ”๋“œ๋กœ๋„ ๋™์ž‘ํ•˜์ง€๋งŒ ๋ฌธ์ž์—ด ๋ณ€ํ™˜ -> ๋’ค์ง‘๊ธฐ -> ๋‹ค์‹œ ๋ฌธ์ž์—ด ํŒŒ์‹ฑ์˜ ๊ณผ์ •์„ ๊ฑฐ์น˜์ง€ ์•Š๊ณ 
22+
* ๋น„ํŠธ๋ฅผ ์กฐ์ž‘ํ•˜๋Š” ๊ฒƒ์ด ๋ฌธ์ œ์˜ ์˜๋„์— ๋” ๋ถ€ํ•ฉํ•จ.
23+
*
24+
class Solution {
625
726
public static String toBinaryString(int value) {
827
String str = Integer.toBinaryString(value);
@@ -20,3 +39,4 @@ public int reverseBits(int n) {
2039
return result;
2140
}
2241
}
42+
*/

0 commit comments

Comments
ย (0)