글
[LeetCode][0003] Longest Substring Without Repeating Characters
LeetCode
2020. 6. 12. 00:25
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int left = 0, right = 0, ret = 0;
unordered_map<char, int> m;
while(right < s.size()) {
if(m.find(s[right]) != m.end()) {
left = max(left, m[s[right]] + 1);
}
ret = max(ret, right - left + 1);
m[s[right]] = right;
++right;
}
return ret;
}
};