leetcode

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

1695.cpp (500B)


      1 class Solution {
      2   public:
      3     int maximumUniqueSubarray(const vector<int> &nums) const {
      4         static bool seen[10001];
      5         memset(seen, 0x00, sizeof(seen));
      6         int res = 0, sum = 0, i = 0;
      7         for (int j = 0; j < nums.size(); j++) {
      8             while (seen[nums[j]]) {
      9                 seen[nums[i]] = 0;
     10                 sum -= nums[i++];
     11             }
     12             seen[nums[j]] = 1;
     13             sum += nums[j];
     14             res = max(res, sum);
     15         }
     16         return res;
     17     }
     18 };