can balance coding bat solution

Solutions on MaxInterview for can balance coding bat solution by the best coders in the world

showing results for - "can balance coding bat solution"
Arianna
19 Nov 2020
1public boolean canBalance(int[] nums) {
2  int a= nums.length;
3  int b=nums[0];
4  int flag=0;
5  if (a>2) {
6    for (int i = 1; i < nums.length; i++) {
7        b = b + nums[i];
8        b = b;
9        int sum = 0;
10        for (int j = i + 1; j < nums.length; j++) {
11          sum = sum + nums[j];
12        }
13        if (sum == b) {
14          flag=1;
15            break;
16        } 
17        else {
18          flag=0;
19        }
20    }
21  }
22  else if (nums.length==2){
23    int q=nums[0];
24    int w=nums[1];
25    if (q==w){
26      flag=1;
27    }
28    else{
29      flag=0;
30    }
31  }
32  else{
33    flag=0;
34  }
35  if (flag==0){
36    return false;
37  }
38  else{
39    return true;
40  }
41}
42// Thank you
similar questions
fix45 codingbat solution