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

Commit1251353

Browse files
authored
Merge pull requestneetcode-gh#1610 from a93a/438
Create 438-Find-All-Anagrams-In-A-String.kt
2 parentsd49b16e +da0dca2 commit1251353

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
classSolution {
2+
funfindAnagrams(s:String,p:String):List<Int> {
3+
4+
val pCount=IntArray(26)
5+
val res=ArrayList<Int>()
6+
7+
for(cin p)
8+
pCount[c-'a']++
9+
10+
var start=0
11+
var end=0
12+
13+
while(end< s.length){
14+
// increase the window
15+
if(pCount[s[end]-'a']>0){
16+
pCount[s[end++]-'a']--
17+
if(end-start== p.length)
18+
res.add(start)
19+
// window size 0? step to next
20+
}elseif(start== end){
21+
start++
22+
end++
23+
//decrease the window
24+
}else{
25+
pCount[s[start++]-'a']++
26+
}
27+
}
28+
29+
return res
30+
}
31+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp