File tree Expand file tree Collapse file tree
longest-repeating-character-replacement Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments