You are viewing a single comment's thread. Return to all comments →
Will it become faster if we seprate if conditions< like this ` static int equalStacks(int[] h1, int[] h2, int[] h3) {
Stack<Integer> s1 = new Stack(); Stack<Integer> s2 = new Stack(); Stack<Integer> s3 = new Stack(); int sum1=0,sum2=0,sum3=0; for(int i=h1.length-1;i>-1;i--){ s1.push(h1[i]); sum1+=h1[i]; } for(int j=h2.length-1;j>-1;j--){ s2.push(h2[j]); sum2+=h2[j]; } for(int k=h3.length-1;k>-1;k--){ s3.push(h3[k]); sum3 +=h3[k]; } while(true){ if(sum1==sum2&&sum2==sum3) break; if(sum1<sum2){ sum2 -=s2.peek(); s2.pop(); } if(sum1<sum3){ sum3-=s3.peek(); s3.pop(); } if(sum2<sum1){ sum1 -=s1.peek(); s1.pop(); } if(sum2<sum3){ sum3 -=s3.peek(); s3.pop(); } if(sum3<sum1){ sum1 -=s1.peek(); s1.pop(); } if(sum3<sum2){ sum2 -=s2.peek(); s2.pop(); } } return sum1 ;
}`
Equal Stacks
You are viewing a single comment's thread. Return to all comments →
Will it become faster if we seprate if conditions< like this ` static int equalStacks(int[] h1, int[] h2, int[] h3) {
}`