leetcode

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

2401.cpp (352B)


      1 class Solution {
      2   public:
      3     int longestNiceSubarray(const vector<int> &nums) const {
      4         int res = 0, used = 0, j = 0;
      5 
      6         for (int i = 0; i < size(nums); i++) {
      7             while (used & nums[i])
      8                 used ^= nums[j++];
      9             used |= nums[i];
     10             res = max(res, i - j);
     11         }
     12 
     13         return res + 1;
     14     }
     15 };