From LeetCode medium 3. Longest Substring Without Repeating Characters:Given a string, find the length of the longest substring without repeating characters.Examples:Given abcabcbb, the answer is abc, which the length is 3.Given bbbbb, the answer is b, with the length of 1.Given pwwkew, the answer is wke, with the length of 3. Note that the answer must be a substring, pwke is a subsequence and not a substring.Here is my solution, but the online judge told me Time Limit Exceeded. Is there a better solution to this problem?private extension String{    subscript (index:Int) -> Character    {        return (self[self.startIndex.advancedBy(index)])    }}class Solution{    func lengthOfLongestSubstring(s: String) -> Int    {        var str:String =         var longest:Int = Int.min        if s.isEmpty        {            return 0        }        for i in 0...s.characters.count-1        {            if !str.characters.contains(s[i])            {                str += String(s[i])            }            else            {                longest = max(longest, str.characters.count)                str =             }        }        return longest    }}
Swift solution to Leetcode Longest Substring Without Repeating Characters
strings;programming challenge;time limit exceeded;swift