Problem
Given a string, find the length of the oldest string that does not contain repeating characters.
Example:
Given "abcabcbb"
that the oldest string without repeating characters is "abc"
, then the length is 3.
Given "bbbbb"
, the longest substring is, the "b"
length is 1.
Given "pwwkew"
that the eldest string is "wke"
, the length is 3. Note that the answer must be a substring, "pwke"
which is a subsequence and not a substring
Code implementation
Class Solution {public: int lengthoflongestsubstring (string s) { //cout << s << endl; uint64_t size = s.length (), begin = 0, end = 0, max_length = 0; for (int end = 0, end < size; end++) {for (int j = begin; J < End; J + +) { //cout << begin << "\ T "<< end << Endl; if (s[j] = = S[end]) { begin = j + 1; Continue; } } if (End-begin + 1 > Max_length) { max_length = end-begin + 1; } } cout << max_length << Endl; return max_length;} ;
Recommended
"Leetcode" algorithm question 3 the oldest string with no repeating characters