Given a string s, find the length of the longest substring without repeating characters.

&nbsp;
Example 1:

Input: s = "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.


Example 2:

Input: s = "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.


Example 3:

Input: s = "pwwkew"
Output: 3
Explanation: The answer is "wke", with the length of 3.
Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.


&nbsp;
Constraints:


	0 &lt;= s.length &lt;= 5 * 104
	s consists of English letters, digits, symbols and spaces.


class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        
        longest_s = ''
        curr_s = ''
        for i in s:
            if i not in curr_s:
                curr_s += i
                if len(curr_s) >= len(longest_s):
                    longest_s = curr_s
            else:
                curr_s = curr_s[curr_s.index(i)+1:]+i
        
        return len(longest_s)
class Solution {
    public int lengthOfLongestSubstring(String s) {
        Map<Character, Integer> hash = new HashMap<>();
        int count = 0;
        int ans = 0;
        for(int i=0; i < s.length(); i++){
            if(hash.containsKey(s.charAt(i))){
                i = hash.get(s.charAt(i)) + 1;
                hash.clear();
                count = 0;
            }
            if(!hash.containsKey(s.charAt(i))){
                hash.put(s.charAt(i), i);
                count++;
                ans = Math.max(ans, count);
            }
        }
        return ans;
    }
}
class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        map<char, int> mp;
        int ans = 1;
        for(auto ch : s) {
            if(mp.find(ch) != mp.end()) {
                while(mp.find(ch) != mp.end()) mp.erase(mp.begin());
            }
            mp.insert({ch, 1});
            if(mp.size() > ans) ans = mp.size();
        }
        return ans;
    }
};
var lengthOfLongestSubstring = function(s) {
    // keeps track of the most recent index of each letter.
    const seen = new Map();
    // keeps track of the starting index of the current substring.
    let start = 0;
    // keeps track of the maximum substring length.
    let maxLen = 0;

    for(let i = 0; i < s.length; i++) {
        // if the current char was seen, move the start to (1 + the last index of this char)
        // max prevents moving backward, 'start' can only move forward
        if(seen.has(s[i])) start = Math.max(seen.get(s[i]) + 1, start)
        seen.set(s[i], i);
        // maximum of the current substring length and maxLen
        maxLen = Math.max(i - start + 1, maxLen);
    }

    return maxLen;
};
Longest Substring Without Repeating Characters