We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c2e782b commit cfd3c2cCopy full SHA for cfd3c2c
longest-substring-without-repeating-characters/doitduri.swift
@@ -0,0 +1,20 @@
1
+class Solution {
2
+ func lengthOfLongestSubstring(_ s: String) -> Int {
3
+ var charIndexMap = [Character: Int]()
4
+ var maxLength = 0
5
+ var startIndex = 0
6
+
7
+ for (i, char) in Array(s).enumerated() {
8
+ if let lastIndex = charIndexMap[char], lastIndex >= startIndex {
9
+ startIndex = lastIndex + 1
10
+ }
11
12
+ let currentLength = i - startIndex + 1
13
+ maxLength = max(maxLength, currentLength)
14
15
+ charIndexMap[char] = i
16
17
18
+ return maxLength
19
20
+}
0 commit comments