leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0003.cpp (356B)


      1 class Solution {
      2   public:
      3     int lengthOfLongestSubstring(string s) {
      4         int maxi = 0;
      5         unordered_set<char> us;
      6         for (int i = 0, j = 0; j < size(s); j++) {
      7             while (us.count(s[j]))
      8                 us.erase(s[i++]);
      9             maxi = max(j - i + 1, maxi);
     10             us.insert(s[j]);
     11         }
     12         return maxi;
     13     }
     14 };