File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 1
1
plugins {
2
2
id ' java'
3
+ id ' org.jetbrains.kotlin.jvm' version ' 1.3.21'
3
4
}
4
5
5
6
group ' group.redspider'
@@ -13,4 +14,15 @@ repositories {
13
14
14
15
dependencies {
15
16
testCompile group : ' junit' , name : ' junit' , version : ' 4.12'
17
+ compile " org.jetbrains.kotlin:kotlin-stdlib-jdk8"
18
+ }
19
+ compileKotlin {
20
+ kotlinOptions {
21
+ jvmTarget = " 1.8"
22
+ }
23
+ }
24
+ compileTestKotlin {
25
+ kotlinOptions {
26
+ jvmTarget = " 1.8"
27
+ }
16
28
}
Original file line number Diff line number Diff line change
1
+ package N1_100
2
+
3
+ import org.junit.jupiter.api.Assertions.assertEquals
4
+ import org.junit.jupiter.api.Test
5
+ import kotlin.math.max
6
+
7
+ class Solution {
8
+ fun lengthOfLongestSubstring (s : String ): Int {
9
+ var maxLength = 0
10
+ val n = s.length
11
+ val map = HashMap <Char , Int >()
12
+ var i = 0
13
+ for (j in 0 until n) {
14
+ if (s[j] in map) {
15
+ i = max(map.get(s[j])!! , i)
16
+ }
17
+ maxLength = max(maxLength, j - i + 1 )
18
+ map.put(s[j], j + 1 )
19
+ }
20
+ return maxLength
21
+ }
22
+
23
+ @Test
24
+ fun test () {
25
+ assertEquals(lengthOfLongestSubstring(" abcabcbb" ), 3 )
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments