✅ [Accepted] Solution for Swift
\nDisclaimer: By using any content from this post or thread, you release the author(s) from all liability and warranty of any kind. You are free to use the cont
<blockquote>\n<b>Disclaimer:</b> By using any content from this post or thread, you release the author(s) from all liability and warranty of any kind. You are free to use the content freely and as you see fit. Any suggestions for improvement are welcome and greatly appreciated! Happy coding!\n</blockquote>\n\n```swift\nclass Solution {\n    func lengthOfLongestSubstring(_ s: String) -> Int {\n        var len = 0, chars = [Character]()\n        for c in s {\n            if let idx = chars.firstIndex(of: c) {\n                chars.removeSubrange(0...idx)\n            }\n            chars.append(c)\n            len = max(len, chars.count)\n        }\n        return len\n    }\n}\n```\n\n<b>Playground and test cases: https://leetcode.com/playground/RCFf98E3</b>
['Swift']