C++ Solution


  • 0
    bool checkSubarraySum(vector<int>& nums, int k) {
            vector<int> sumNums(nums.begin(), nums.end());
            
            for(int j=1; j<nums.size(); ++j)
            {
                for(int i=0;i+j<nums.size(); ++i)
                {
                    sumNums[i] += nums[i+j];
                    if(k==0)
                    { 
                        if(sumNums[i]==0) return true;
                    }
                    else if(sumNums[i]%k == 0) return true;
                }
            }
            return false;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.