Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public boolean solution(int[] A) {
- // write your code in Java SE 8
- int sumL = 0;
- int sumR = 0;
- int sumM = 0;
- int indexL = 1;
- int indexR = A.length - 2;
- for(int m=indexL+1;m<indexR;m++){
- sumM+=A[m];
- }
- for(int i=0;i<A.length-2;i++){
- sumL+=A[indexL-1];
- sumR+=A[indexR+1];
- if(sumL==sumR && sumL==sumM){
- return true;
- }
- if(sumL < sumR){
- indexL++;
- sumM-=A[indexL];
- } else if(sumR <= sumL){
- indexR--;
- sumM-=A[indexR];
- } else if(sumM < sumL && sumM < sumR){
- return false;
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement