How to optimally divide an array into two subarrays so that sum of elements in both are same, otherwise give an error?

前端 未结 22 971
一生所求
一生所求 2020-12-02 11:20

How to optimally divide an array into two subarrays so that sum of elements in both subarrays is same, otherwise give an error?

Example 1

Given the array

22条回答
  •  北海茫月
    2020-12-02 12:13

        public boolean splitBetween(int[] x){
        int sum=0;
        int sum1=0;
        if (x.length==1){
            System.out.println("Not a valid value");
        }
    
        for (int i=0;i

提交回复
热议问题