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 {
1212 let array = Array ( s)
1313
1414 var set : Set < Character > = [ ]
15- var temp : Int = 0
1615 var startIndex = 0
1716 for index in array. indices {
1817 if set. contains ( array [ index] ) == false {
1918 set. insert ( array [ index] )
20- temp += 1
2119 continue
2220 }
2321
24- if longest < temp {
25- longest = temp
22+ if longest < index - startIndex {
23+ longest = index - startIndex
2624 }
2725
2826 while array [ startIndex] != array [ index] {
2927 set. remove ( array [ startIndex] )
30- temp -= 1
3128 startIndex += 1
3229 }
3330 startIndex += 1
3431 }
3532
36- if longest < temp {
37- longest = temp
33+ if longest < array . endIndex - startIndex {
34+ longest = array . endIndex - startIndex
3835 }
3936
37+
4038 return longest
4139 }
4240}
You can’t perform that action at this time.
0 commit comments