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

Commit2017c2b

Browse files
authored
Add Kotlin leetcode 3
1 parent0483b96 commit2017c2b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
classSolution {
2+
funlengthOfLongestSubstring(s:String):Int {
3+
val hs=HashSet<Char>()
4+
var i=0
5+
var j=0
6+
var maxLength=0
7+
while (j< s.length) {
8+
if (hs.contains(s[j])) {
9+
hs.remove(s[i++])
10+
}else {
11+
hs.add(s[j++])
12+
maxLength= maxLength.coerceAtLeast(hs.size)
13+
}
14+
}
15+
return maxLength
16+
}
17+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp