Skip to content

Commit 19931e7

Browse files
BarklimBarklim
Barklim
authored and
Barklim
committed
Create 0424.js
1 parent 853055b commit 19931e7

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

0424-longest-repeating-character-replacement.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,28 @@ var characterReplacement = function(s, k) {
3030
return Math.max(maxLength, right - left + 1);
3131
}, 0);
3232
};
33+
34+
// var characterReplacement = function(s, k) {
35+
// const window_state = new Set(s); // charSet
36+
// let result = 0;
37+
38+
// for (let char of window_state) {
39+
// let begin = 0;
40+
// let count = 0
41+
// for (let end = 0; end < s.length; end++) {
42+
// if (s[end] === char) {
43+
// count++;
44+
// }
45+
46+
// while ((end - begin + 1) - count > k) {
47+
// if (s[begin] === char) {
48+
// count--;
49+
// }
50+
// begin++;
51+
// }
52+
53+
// result = Math.max(result, end - begin + 1);
54+
// }
55+
// }
56+
// return result;
57+
// };

example/2.SlidingWindow/0424.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* 424. Longest Repeating Character Replacement
3+
* https://leetcode.com/problems/longest-repeating-character-replacement/
4+
* Difficulty: Medium
5+
*
6+
* You are given a string s and an integer k. You can choose any character of the string
7+
* and change it to any other uppercase English character. You can perform this operation
8+
* at most k times.
9+
*
10+
* Return the length of the longest substring containing the same letter you can get after
11+
* performing the above operations.
12+
*/
13+
14+
/**
15+
* @param {string} s
16+
* @param {number} k
17+
* @return {number}
18+
*/
19+
var characterReplacement = function(s, k) {
20+
21+
};
22+
23+
const example1 = characterReplacement("ABAB", 2); // 4
24+
const example2 = characterReplacement("AABABBA", 1); // 4
25+
const example3 = characterReplacement("XYYX", 2); // 4
26+
const example4 = characterReplacement("AAABABB", 1); // 5
27+
const example5 = characterReplacement("", 1); // 0
28+
const example6 = characterReplacement("AAABBBXXXAABBXX", 1); // 4
29+
const example7 = characterReplacement("AAABBBXXXAABBXX", 2); // 5
30+
const example8 = characterReplacement("AAABBBXXXAABBXX", 3); // 6
31+
32+
console.log(example1);
33+
console.log(example2);
34+
console.log(example3);
35+
console.log(example4);
36+
console.log(example5);
37+
console.log(example6);
38+
console.log(example7);
39+
console.log(example8);

0 commit comments

Comments
 (0)