题目:
代码:
class Solution {
public:
vector<int> sortedSquares(vector<int>& A) {
int begin=0,end=A.size();
vector<int> ans(end);
int num=end-1;
while(begin<end){
if(A[begin]*A[begin]>A[end-1]*A[end-1]){
ans[num]=A[begin]*A[begin];
begin++;
}
else{
ans[num]=A[end-1]*A[end-1];
end--;
}
num--;
}
return ans;
}
};