标签:
For this problem, we are OK to use hash set, since no numbers are needed.
1 class Solution { 2 public: 3 int lengthOfLongestSubstring(string s) { 4 int len = s.size(), result = 0; 5 if (len < 2) return len; 6 unordered_set<char> sets; 7 for (int left = 0, right = 0; right < len; right++) { 8 if (sets.find(s[right]) == sets.end()) { 9 result = max(result, right - left + 1); 10 sets.insert(s[right]); 11 } else { 12 sets.erase(s[left++]); 13 right--; 14 } 15 } 16 return result; 17 } 18 };
LeetCode – Refresh – Longest Substring Without Repeating Characters
标签:
原文地址:http://www.cnblogs.com/shuashuashua/p/4352702.html