(Easy) Last Stone Weight LeetCode

Posted codingyangmao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了(Easy) Last Stone Weight LeetCode相关的知识,希望对你有一定的参考价值。

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];
        
        
    

 

以上是关于(Easy) Last Stone Weight LeetCode的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode 1049. Last Stone Weight II

LeetCode --- 1046. Last Stone Weight 解题报告

1046. Last Stone Weight

LeetCode --- 1046. Last Stone Weight 解题报告

动态规划-Last Stone Weight II

LeetCode 1046. Last Stone Weight (最后一块石头的重量 )