-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ2.cpp
More file actions
32 lines (24 loc) · 634 Bytes
/
Q2.cpp
File metadata and controls
32 lines (24 loc) · 634 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<bits/stdc++.h>
using namespace std;
int lengthOfLongestSubstring(string s)
{
vector<int> mpp(256, -1);
int left = 0;
int right = 0;
int n = s.size();
int maxLen = 0;
while (right < n) {
if (mpp[s[right]] != -1) {
left = max(mpp[s[right]] + 1, left);
}
mpp[s[right]] = right;
maxLen = max(maxLen, right - left + 1);
right++;
}
return maxLen;
}
int main() {
string s = "abcdefgabchefui";
cout << "The length of the longest substring without repeating characters is: " << lengthOfLongestSubstring(s) << endl;
return 0;
}