add: 220407 [cpp]
This commit is contained in:
parent
ba5dd1c5f2
commit
2251e072ea
|
|
@ -0,0 +1,24 @@
|
|||
#include <vector>
|
||||
#include <queue>
|
||||
#include <iostream>
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
static int lastStoneWeight(const std::vector<int>& stones) {
|
||||
std::priority_queue<int> q(stones.begin(), stones.end());
|
||||
while (q.size() > 1) {
|
||||
int x = q.top();
|
||||
q.pop();
|
||||
x = std::abs(q.top() - x);
|
||||
q.pop();
|
||||
if (x)
|
||||
q.push(x);
|
||||
}
|
||||
return q.empty() ? 0 : q.top();
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
std::cout << Solution::lastStoneWeight({1, 3});
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -3,4 +3,4 @@ PROJECT(2204)
|
|||
|
||||
SET(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
ADD_EXECUTABLE(2204 220407-CN.cpp)
|
||||
ADD_EXECUTABLE(2204 220407.cpp)
|
||||
|
|
|
|||
Loading…
Reference in New Issue