feat: 2025-10-23打卡
This commit is contained in:
24
1046.last-stone-weight.java
Normal file
24
1046.last-stone-weight.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* @lc app=leetcode id=1046 lang=java
|
||||
*
|
||||
* [1046] Last Stone Weight
|
||||
*/
|
||||
|
||||
// @lc code=start
|
||||
class Solution {
|
||||
public int lastStoneWeight(int[] stones) {
|
||||
PriorityQueue<Integer> pq = new PriorityQueue<>((a, b)->b-a);
|
||||
for(int i = 0; i < stones.length; i++) {
|
||||
pq.add(stones[i]);
|
||||
}
|
||||
int a, b;
|
||||
while(pq.size() > 1) {
|
||||
a = pq.poll();
|
||||
b = pq.poll();
|
||||
pq.add(a < b?b-a:a-b);
|
||||
}
|
||||
return pq.peek();
|
||||
}
|
||||
}
|
||||
// @lc code=end
|
||||
|
||||
Reference in New Issue
Block a user