Longest substrings without repeating characters: Difference between revisions

m
Simplified C++ code
(Added C++ solution)
m (Simplified C++ code)
Line 19:
std::vector<std::string> longest_substrings_without_repeats(const std::string& str) {
size_t max_length = 0;
std::vector<size_tstd::string> offsetsresult;
size_t length = str.size();
for (size_t offset = 0; offset < length; ++offset) {
Line 30:
}
if (len > max_length) {
offsetsresult.clear();
max_length = len;
}
if (len == max_length)
offsetsresult.push_back(str.substr(offset, max_length));
}
std::vector<std::string> result;
for (size_t offset : offsets)
result.push_back(str.substr(offset, max_length));
return result;
}
1,777

edits