# Longest Substring Without Repeating Characters

## Longest Substring Without Repeating Characters

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

Example 1:

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

Java Solution

``class Solution {    public int lengthOfLongestSubstring(String s) {        HashMap<Character, Integer>mpp = new HashMap<Character, Integer>();                int left=0, right=0;        int n = s.length();        int len=0;                while(right<n){            if(mpp.containsKey(s.charAt(right)))            left = Math.max(mpp.get(s.charAt(right))+1,left);                        mpp.put(s.charAt(right), right);            len=Math.max(len, right-left + 1);            right++;        }        return len;    }}``

C++ Solution

``class Solution {    public int lengthOfLongestSubstring(String s) {                set<char>Set;                int Max=0;                int start=0;        int end=0;                while(start<s.size()){            auto it = Set.find(s[start]);            if(it==Set.end()){                if(start-end+1>Max)                Max = start - end + 1;                Set.insert(s[Start]);                start++;            }            else{                Set.erase(s[end]);                end++;            }        }    }}``

Explanation will be available soon