Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. class Solution {
  2. public boolean solution(int[] A) {
  3. // write your code in Java SE 8
  4. int sumL = 0;
  5. int sumR = 0;
  6. int sumM = 0;
  7.  
  8. int indexL = 1;
  9. int indexR = A.length - 2;
  10.  
  11. for(int m=indexL+1;m<indexR;m++){
  12. sumM+=A[m];
  13. }
  14. for(int i=0;i<A.length-2;i++){
  15. sumL+=A[indexL-1];
  16. sumR+=A[indexR+1];
  17. if(sumL==sumR && sumL==sumM){
  18. return true;
  19. }
  20. if(sumL < sumR){
  21. indexL++;
  22. sumM-=A[indexL];
  23. } else if(sumR <= sumL){
  24. indexR--;
  25. sumM-=A[indexR];
  26. } else if(sumM < sumL && sumM < sumR){
  27. return false;
  28. }
  29.  
  30. }
  31. return false;
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement