Skip to content

Commit c41cee1

Browse files
authored
Merge pull request #2250 from juhui-jeong/main
[juhui-jeong] Week 08 Solutions
2 parents f9db85f + 1faa71d commit c41cee1

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* 시간복잡도: O(n)
3+
* 공간복잡도: O(1)
4+
*/
5+
class Solution {
6+
public int characterReplacement(String s, int k) {
7+
int left = 0;
8+
int[] freq = new int[26];
9+
int maxFreq = 0;
10+
int ans = 0;
11+
12+
for (int right = 0; right < s.length(); right++) {
13+
int rIdx = s.charAt(right) - 'A';
14+
freq[rIdx]++;
15+
maxFreq = Math.max(maxFreq, freq[rIdx]);
16+
17+
while((right - left + 1) - maxFreq > k) {
18+
int lIdx = s.charAt(left) - 'A';
19+
freq[lIdx]--;
20+
left++;
21+
}
22+
ans = Math.max(ans, right - left + 1);
23+
}
24+
return ans;
25+
}
26+
}

reverse-bits/juhui-jeong.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* 시간 복잡도: O(1)
3+
* 공간 복잡도: O(1)
4+
*/
5+
class Solution {
6+
7+
public static String toBinaryString(int value) {
8+
String str = Integer.toBinaryString(value);
9+
while (str.length() < 32) {
10+
str = "0" + str;
11+
}
12+
return str;
13+
}
14+
15+
public int reverseBits(int n) {
16+
String binaryString = toBinaryString(n);
17+
String reversed = new StringBuilder(binaryString).reverse().toString();
18+
19+
int result = Integer.parseUnsignedInt(reversed, 2);
20+
return result;
21+
}
22+
}

0 commit comments

Comments
 (0)