Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions linked-list-cycle/juhui-jeong.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 시간 복잡도: O(n)
* 공간 복잡도: O(n)
*/
public class Solution {
public boolean hasCycle(ListNode head) {
Set<ListNode> visited = new HashSet<>();
while (head != null) {
if (visited.contains(head)) {
return true;
}
visited.add(head);
head = head.next;
}
return false;
}
}
20 changes: 20 additions & 0 deletions reverse-bits/juhui-jeong.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
* 공간 복잡도: O(1)
*/
class Solution {
public int reverseBits(int n) {
int result = 0;

for (int i = 0; i < 32; i++) {
result = (result << 1) | (n & 1);
n >>= 1;
}
return result;
}
}

/*
* 시간 복잡도: O(1)
* 공간 복잡도: O(32)
*
* 해당 코드로도 동작하지만 문자열 변환 -> 뒤집기 -> 다시 문자열 파싱의 과정을 거치지 않고
* 비트를 조작하는 것이 문제의 의도에 더 부합함.
*
class Solution {

public static String toBinaryString(int value) {
String str = Integer.toBinaryString(value);
Expand All @@ -20,3 +39,4 @@ public int reverseBits(int n) {
return result;
}
}
*/