leetcode

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

0523.cpp (369B)


      1 class Solution {
      2   public:
      3     bool checkSubarraySum(const vector<int> &nums, int k) const {
      4         unordered_set<int> seen;
      5 
      6         for (int i = 0, sum = 0, pre = 0; i < size(nums); i++) {
      7             sum += nums[i];
      8             if (seen.count(sum % k)) return true;
      9             seen.insert(pre);
     10             pre = sum % k;
     11         }
     12 
     13         return false;
     14     }
     15 };