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_set hash;
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;
}
};
3/30/2014
Leetcode -- Longest Substring Without Repeating Characters
Solution 03/30/2014 O(n2)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment