leetcode_977
Solutions
class Solution {
public:
vector<int> sortedSquares(vector<int>& A) {
if (!A.size()) return {};
vector<int> res(A.size());
int i = 0, j = A.size() - 1, w = j;
while (w >= 0) {
if (abs(A[j]) > abs(A[i]))
res[w--] = pow(A[j--], 2);
else
res[w--] = pow(A[i++], 2);
}
return res;
}
};Last updated