File tree 3 files changed +30
-1
lines changed
3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change
1
+ const characterReplacement = ( s , k ) => {
2
+ let max = 0 , char = s . split ( "" ) ;
3
+
4
+ // loop thru the char, to move expand it by k if NOT the same (then decrease the tmpK)
5
+
6
+ for ( let i = 0 ; i < char . length ; i ++ ) {
7
+ for ( let j = i + 1 ; j < char . length ; j ++ ) {
8
+ let count = 0 , tmpK = k ;
9
+ // clean up
10
+ if ( char [ i ] !== char [ j ] ) {
11
+ if ( tmpK > 0 ) {
12
+ // increase count by 1 when same or k > 0 & not the same
13
+ tmpK -- ;
14
+ count ++ ;
15
+ } else { // stop when diff and k == 0
16
+ continue ;
17
+ }
18
+ } else {
19
+ count ++ ;
20
+ }
21
+
22
+ // get max from count and max
23
+ max = Math . max ( max , count ) ;
24
+ }
25
+ }
26
+
27
+ return max ;
28
+ }
Original file line number Diff line number Diff line change 45
45
- [ 371. Sum of Two Integers] ( ./371/ )
46
46
- [ 338. Counting Bits] ( ./338/ )
47
47
- [ 394. Decode String] ( ./394/ )
48
+ - [ 424. Longest Repeating Character Replacement] ( ./424/ )
48
49
49
50
---
50
51
@@ -78,5 +79,5 @@ Batch create in bash
78
79
TODO: Add to TOC!
79
80
-->
80
81
``` ssh
81
- chapter=49 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
82
+ chapter=424 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
82
83
```
You can’t perform that action at this time.
0 commit comments