class Solution {
public:
vector<int> sortedSquares(vector<int>& A) {
if (A.empty()) {
return {};
}
priority_queue<int, vector<int>, greater<int>> q;
for (int num : A) {
q.push(num*num);
}
vector<int> ans;
while (!q.empty()) {
ans.push_back(q.top());
q.pop();
}
return ans;
}
};
每天一题 977. 有序数组的平方
最新推荐文章于 2024-01-26 01:44:29 发布