class Solution {
public:
int lengthOfLongestSubstring(string s) {
const size_t n = s.length();
int maxLength = 0;
for(size_t i = 0; i < n; i++) {
std::unordered_sethash;
for(size_t j = i; j < n; j++) {
if(hash.count(s[j]) > 0) {
break;
} else {
hash.emplace(s[j]);
}
}
maxLength = hash.size() > maxLength ? hash.size() : maxLength;
}
return maxLength;
}
};
No comments:
Post a Comment