Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Check the longest substring without repeating character
  • Loading branch information
vishwas6664 authored Oct 10, 2022
1 parent d771009 commit 597f897
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Longest_Substring.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public:
int lengthOfLongestSubstring(string s) {

unordered_map<char,int> index;
int start=0,res=0;
for(int i=0;i<s.length();i++){

if (index.find(s[i]) != index.end() && index[s[i]] >= start)
start = index[s[i]] + 1;

index[s[i]] = i;
res=max(res,i-start+1);
}

return res;
}
};

0 comments on commit 597f897

Please sign in to comment.