feat: 2025-10-23打卡

This commit is contained in:
wu xiangkai
2025-10-23 16:32:13 +08:00
parent 59f245dda7
commit f06095ad7e
9 changed files with 378 additions and 0 deletions

View 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