class Solution { public int lastStoneWeight(int[] stones) { int len = stones.length; int i = len -1; int minus = 0; int remain = len; if(stones.length ==1){ return stones[0]; } else { Arrays.sort(stones); do{ if(stones[i]==stones[i-1]){ stones[i] = 0; stones[i-1] = 0; remain = remain -2; } else{ stones[i-1]= stones[i]-stones[i-1]; stones[i]=0; remain = remain -1; } Arrays.sort(stones); } while(remain >1); return stones[len-1]; } } }
原文地址:https://www.cnblogs.com/codingyangmao/p/11278051.html
时间: 2024-11-09 03:27:23