The simplest idea. Beats 99%.


  • 0
    Y

    The simplest idea. Beats 99%.

    class Solution {
    public boolean splitArray(int[] nums) {
    int sum0 = 0;

        for(int i = 1; i < nums.length -5; i++){
            if(nums[i-1] == 0) continue;
            sum0 += nums[i-1];
            int sum1 = 0;
            for(int j = i + 2; j < nums.length - 3; j++){
                sum1 += nums[j-1];
                if(sum0 == sum1){
                    int sum2 = 0;
                    for(int k = j + 2; k < nums.length - 1; k++){
                        sum2 += nums[k-1];
                        if(sum2 == sum1){
                            int sum3 = 0;
                            for(int f = k+1; f < nums.length; f++){
                                sum3 += nums[f];
                            }
                            if(sum3 == sum2)    return true;
                        }
                    }
                }
            }
        }
        return false;
    }
    

    }


Log in to reply
 

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