MCPcopy Index your code
hub / github.com/neetcode-gh/leetcode / lastStoneWeight

Method lastStoneWeight

java/1046-last-stone-weight.java:3–12  ·  view source on GitHub ↗
(int[] stones)

Source from the content-addressed store, hash-verified

1class Solution {
2
3 public int lastStoneWeight(int[] stones) {
4 PriorityQueue<Integer> maxHeap = new PriorityQueue();
5 for (int stone : stones) maxHeap.add(-stone);
6 while (maxHeap.size() > 1) {
7 int stone1 = maxHeap.remove();
8 int stone2 = maxHeap.remove();
9 if (stone1 != stone2) maxHeap.add(stone1 - stone2);
10 }
11 return maxHeap.size() != 0 ? (-maxHeap.remove()) : 0;
12 }
13}

Callers

nothing calls this directly

Calls 3

addMethod · 0.45
sizeMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected