Java 100% time 100% space
````\npublic int lastStoneWeight(int[] stones) {\n        if(stones.length==1)return stones[0];\n        Arrays.sort(stones);\n        int y = stones.length-1;\
````\npublic int lastStoneWeight(int[] stones) {\n        if(stones.length==1)return stones[0];\n        Arrays.sort(stones);\n        int y = stones.length-1;\n        int x = stones.length-2;\n        while(x>=0){\n            if(stones[x]==stones[y]){\n                stones[x] = 0;\n                stones[y] = 0;\n            }else{\n                stones[y] -= stones[x];\n                stones[x] = 0;\n            }\n            Arrays.sort(stones);\n            if(stones[x]==0)break;\n        }\n        return stones[y];\n    }
['Java']