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

Commit20a0822

Browse files
committed
Kotlin: 567. Permutation in String
1 parent86f67c2 commit20a0822

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

‎kotlin/567-Permutation-In-String.kt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
classSolution {
2+
funcheckInclusion(s1:String,s2:String):Boolean {
3+
val map=HashMap<Char,Int>()
4+
5+
for (cin s1.toCharArray())
6+
map[c]= map.getOrDefault(c,0)+1
7+
8+
var count= map.size
9+
var st=0
10+
11+
for (endin0..s2.length-1) {
12+
val curr= s2[end]
13+
14+
if (map.containsKey(curr)) {
15+
map[curr]= map[curr]!!-1
16+
if (map[curr]==0)
17+
count--
18+
}
19+
20+
while (count==0) {
21+
val temp= s2[st]
22+
23+
if (map.containsKey(temp)) {
24+
map[temp]= map[temp]!!+1
25+
if (map[temp]!!>0)
26+
count++
27+
}
28+
29+
if (end- st+1== s1.length)
30+
returntrue
31+
32+
st++
33+
}
34+
}
35+
36+
returnfalse
37+
}
38+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp