1046. 最后一块石头的重量
多种写法多种思路,重在参考,莫要争辩!
s
class Solution {
public int lastStoneWeight(int[] stones) {
if(stones.length == 1){
return stones[0];
}
int js = 2;
int end = 0;
while(js > 1){
int x = 0;
int y = 0;
int i,j;
int js1=0,js2=0;
for(i=0;i<stones.length;++i){
if(stones[i]>y){
y = stones[i];
js1 = i;
}
}
for(i=stones.length-1;i>=0;--i){
if(stones[i]==y){
stones[i] = 0;
break;
}
}
for(i=0;i<stones.length;++i){
if(stones[i]>x){
x = stones[i];
js2 = i;
}
}
stones[js1] = y-x;
stones[js2] = 0;
js = 0;
end =0;
for(int s : stones){
if(s != 0){
js++;
if(js>1){
break;
}
end = s;
}
}
}
return end;
}
}
h
1