diff --git a/Longest_Substring.cpp b/Longest_Substring.cpp new file mode 100644 index 0000000..5ed5941 --- /dev/null +++ b/Longest_Substring.cpp @@ -0,0 +1,18 @@ +class Solution { +public: + int lengthOfLongestSubstring(string s) { + + unordered_map index; + int start=0,res=0; + for(int i=0;i= start) + start = index[s[i]] + 1; + + index[s[i]] = i; + res=max(res,i-start+1); + } + + return res; + } +}; \ No newline at end of file