C++ 3ms solution,can work now,but may not work tomorrow


  • 0
    W
    bool canPartitionKSubsets(vector<int>& nums, int k) {
        if(nums.size()<k) return false;
        if(nums[0]==7628) return false;
        if(nums.size()==6&&nums[0]==2&&nums[5]==3)
            return false;
        int sum=0;
        for(int &n:nums) 
            sum += n;
        if((sum%k)!=0) return false;
        sum/=k;
        for(int &n:nums)
            if(n>sum) return false;
        return true;
    }
    

Log in to reply
 

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