We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 82bdead commit cd53256Copy full SHA for cd53256
longest-substring-without-repeating-characters/delight010.swift
@@ -0,0 +1,24 @@
1
+class Solution {
2
+ func lengthOfLongestSubstring(_ s: String) -> Int {
3
+ if s.isEmpty {
4
+ return 0
5
+ }
6
+ var maxLength = 0
7
+ var startIndex = 0
8
+ var charSet: Set<Character> = []
9
+ let charArray = Array(s)
10
+
11
+ for right in 0..<charArray.count {
12
+ while charSet.contains(charArray[right]) {
13
+ charSet.remove(charArray[startIndex])
14
+ startIndex += 1
15
16
17
+ charSet.insert(charArray[right])
18
+ maxLength = max(maxLength, right - startIndex + 1)
19
20
21
+ return maxLength
22
23
+}
24
0 commit comments