diff --git a/CPP/Longest_Substring_Without_Repeating_Characters.cpp b/CPP/Longest_Substring_Without_Repeating_Characters.cpp new file mode 100644 index 0000000..3c35ae9 --- /dev/null +++ b/CPP/Longest_Substring_Without_Repeating_Characters.cpp @@ -0,0 +1,60 @@ +/** + * @author: Jatin Garg + * github(https://github.com/jatin-773762) + **/ + +#include +using namespace std; + +/** + * Test Cases: + * 1) s= "abcabcbb" + * output: 3 (abc) + * 2) s="bbbbb" + * output: 1 (b) + **/ + +int lengthOfLongestSubstring(string s) { + + // check if the string is empty or not + if(s.empty()){ + return 0; + } + // vector to store the presence of character + vector vis(256); + for(int i=0;i<256;i++){ + vis[i]=false; + } + int ans=1; + int count=0; + for(int i=0;i>s; + + // prints the length of the longest substring with no repeating characters + cout<