class Solution {
public:
int lengthOfLongestSubstring(string s) {
int res = 0, left = -1, n = s.size();
unordered_map<int, int> m;
for (int i = 0; i < n; ++i) {
if (m.count(s[i]) && m[s[i]] > left) {
left = m[s[i]];
}
m[s[i]] = i;
res = max(res, i - left);
}
return res;
}
};
相关文章
- 03-28*3. Longest Substring Without Repeating Characters
- 03-283. Longest Substring Without Repeating Characters
- 03-28Longest Substring Without Repeating Characters
- 03-283. Longest Substring Without Repeating Characters
- 03-283. Longest Substring Without Repeating Characters
- 03-283.Longest Substring Without Repeating Characters
- 03-28Longest Substring Without Repeating Characters ---- LeetCode 003
- 03-28【一天一道LeetCode】 #3 Longest Substring Without Repeating Characters
- 03-28Leetcode 3. Longest Substring Without Repeating Characters
- 03-28leetcode 3. Longest Substring Without Repeating Characters