Skip to content

Commit 2017c2b

Browse files
authored
Add Kotlin leetcode 3
1 parent 0483b96 commit 2017c2b

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+
class Solution {
2+
fun lengthOfLongestSubstring(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)