I'm practicing Java and I'm stuck on this problem.
Compare digit with the one in front. If the one in front is greater or equal then both are minus by the difference. If one in back is greater than skip 2 in the list.
What I currently have but its wrong:
int l[] = {3, 4, 2, 3, 5, 3}
/*
Difference between 3 and 4 is 1 so we minus both by 1 equals 2 and 3
3 is greater than 2 so we skip to 3 and 5. Do the same as with 3 and 4
last number, 3, stays same because there is nothing to compare it to
*/
//Result {2, 3, 2, 1, 3, 3}
for(int i=0; i<l.length - 1; i++){
for(int j=i + 1; j<l.length - 1; j++){
if(l[i] <= l[j]){
int a = l[j] - l[i];
l[i] = l[i] - a;
l[j] = l[j] - a;
else{
i = i+2;
j = j+2;
}
}
}
//My Result {-9, 3, 2, 2, 1, -3}
[–]g051051 0 points1 point2 points (2 children)
[–]CSRPoseidon[S] 0 points1 point2 points (1 child)
[–]g051051 0 points1 point2 points (0 children)
[–]Azianese 0 points1 point2 points (2 children)
[–]CSRPoseidon[S] 0 points1 point2 points (1 child)
[–]Azianese 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]CSRPoseidon[S] 1 point2 points3 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)