Arrays.sort(stones);
int len = stones.length;
if(len == 0){
return 0;
}
if(len == 1){
return 1;
}
while(stones[len-1] != 0 ){
if(stones[len-1] == 0){
break;
}
if(stones[len-1] != 0 && stones[len-1-1] == 0){
break;
}
if(stones[len-1] == stones[len-1-1]){
stones[len-1] =0;
stones[len-1-1] = 0;
} else {
stones[len-1-1] = stones[len-1] - stones[len-1-1];
stones[len-1] = 0;
}
Arrays.sort(stones);
}
return stones[len - 1];