File tree Expand file tree Collapse file tree 1 file changed +5
-7
lines changed
longest-substring-without-repeating-characters Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Original file line number Diff line number Diff line change @@ -12,31 +12,29 @@ class Solution {
12
12
let array = Array ( s)
13
13
14
14
var set : Set < Character > = [ ]
15
- var temp : Int = 0
16
15
var startIndex = 0
17
16
for index in array. indices {
18
17
if set. contains ( array [ index] ) == false {
19
18
set. insert ( array [ index] )
20
- temp += 1
21
19
continue
22
20
}
23
21
24
- if longest < temp {
25
- longest = temp
22
+ if longest < index - startIndex {
23
+ longest = index - startIndex
26
24
}
27
25
28
26
while array [ startIndex] != array [ index] {
29
27
set. remove ( array [ startIndex] )
30
- temp -= 1
31
28
startIndex += 1
32
29
}
33
30
startIndex += 1
34
31
}
35
32
36
- if longest < temp {
37
- longest = temp
33
+ if longest < array . endIndex - startIndex {
34
+ longest = array . endIndex - startIndex
38
35
}
39
36
37
+
40
38
return longest
41
39
}
42
40
}
You can’t perform that action at this time.
0 commit comments