Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfda9a29

Browse files
committed
Create: 424-Longest-Repeating-Character-Replacement.ts
1 parente64aced commitfda9a29

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
functioncharacterReplacement(s:string,k:number):number{
2+
constcharCount={};
3+
4+
letmax=0;
5+
6+
letdomChar=0;
7+
8+
letl=0;
9+
10+
for(letr=0;r<s.length;r++){
11+
if(s[r]incharCount)charCount[s[r]]++;
12+
elsecharCount[s[r]]=1;
13+
14+
domChar=Math.max(domChar,charCount[s[r]]);
15+
16+
//if the window size minus the count of the dominant character(number of replacements needed) is bigger than k, invalid
17+
while(r-l+1-domChar>k){
18+
charCount[s[l]]--;
19+
if(charCount[s[l]]===0)deletecharCount[s[l]];
20+
l++;
21+
}
22+
23+
max=Math.max(max,r-l+1);
24+
}
25+
26+
returnmax;
27+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp