Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Problem: Longest Substring Without Repeating Characters
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
int lengthofLongestSubstring(string s) {
vector < int > mpp(256, -1);

int left = 0, right = 0;
int n = s.size();
int len = 0;
while (right < n) {
if (mpp[s[right]] != -1)
left = max(mpp[s[right]] + 1, left);

mpp[s[right]] = right;

len = max(len, right - left + 1);
right++;
}
return len;
}
};

int main() {
string str = "takeUforward";
Solution obj;
cout << "The length of the longest substring without repeating characters is " << obj.lengthofLongestSubstring(str);
return 0;
}
Loading