leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0003.cpp (356B)
0 class Solution {
1 public:
2 int lengthOfLongestSubstring(string s) {
3 int maxi = 0;
4 unordered_set<char> us;
5 for (int i = 0, j = 0; j < size(s); j++) {
6 while (us.count(s[j]))
7 us.erase(s[i++]);
8 maxi = max(j - i + 1, maxi);
9 us.insert(s[j]);
10 }
11 return maxi;
12 }
13 };