Java8 Stream solution O(n^2)


  • 0
    Z
    public boolean splitArray(int[] nums) {
            long[] sum = new long[nums.length+1];
            IntStream.range(0, nums.length).forEach(i->sum[i+1]=sum[i]+nums[i]);
            return IntStream.range(0, nums.length-1).anyMatch(i->{
                return IntStream.range(i+1, nums.length).anyMatch(j->{
                    return sum[i]==sum[j]-sum[i+1] && sum[i]==sum[nums.length]-sum[j+1];
                });
            });
        }
    

Log in to reply
 

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