From 02df72eea5f977ac9868221d4625368a75089c44 Mon Sep 17 00:00:00 2001 From: vishwas6664 <67286539+vishwas6664@users.noreply.github.com> Date: Tue, 11 Oct 2022 00:29:46 +0530 Subject: [PATCH] Add files via upload Check longest substring without repeating charecter --- Longest_Substring.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Longest_Substring.cpp 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