题目描述
blablabla
样例
blablabla
算法1
(双指针) $O(n)$
又是一道双指针算法的类型题
时间复杂度
参考文献
C++ 代码
class Solution {
public:
vector<int> sortedSquares(vector<int>& a) {
int i=0,n = a.size() , j = n-1,k = n-1;
vector<int> res(n);
while(i <= j)
{
int left = a[i]*a[i],right = a[j]*a[j];
if(left > right) res[k--] = left,i++;
else res[k--] = right,j--;
}
return res;
}
};