Skip to content

Commit a142303

Browse files
committed
refactor: Refactor code of problem 3
1 parent c957612 commit a142303

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

longest-substring-without-repeating-characters/WhiteHyun.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)