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
26 changes: 26 additions & 0 deletions longest-repeating-character-replacement/juhui-jeong.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 시간복잡도: O(n)
* 공간복잡도: O(1)
*/
class Solution {
public int characterReplacement(String s, int k) {
int left = 0;
int[] freq = new int[26];
int maxFreq = 0;
int ans = 0;

for (int right = 0; right < s.length(); right++) {
int rIdx = s.charAt(right) - 'A';
freq[rIdx]++;
maxFreq = Math.max(maxFreq, freq[rIdx]);

while((right - left + 1) - maxFreq > k) {
int lIdx = s.charAt(left) - 'A';
freq[lIdx]--;
left++;
}
ans = Math.max(ans, right - left + 1);
}
return ans;
}
}
22 changes: 22 additions & 0 deletions reverse-bits/juhui-jeong.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 시간 복잡도: O(1)
* 공간 복잡도: O(1)
*/
class Solution {

public static String toBinaryString(int value) {
String str = Integer.toBinaryString(value);
while (str.length() < 32) {
str = "0" + str;
}
return str;
}

public int reverseBits(int n) {
String binaryString = toBinaryString(n);
String reversed = new StringBuilder(binaryString).reverse().toString();

int result = Integer.parseUnsignedInt(reversed, 2);
return result;
}
}