今天打卡一题,后面两题明天补上
977.有序数组的平方
力扣https://leetcode.cn/problems/squares-of-a-sorted-array/暴力解法:
class Solution {
public:
vector<int> sortedSquares(vector<int>& nums) {
//int faster = 0;
int slower = 0;
for(int faster =0;faster<nums.size();faster++,slower++)
{
nums[slower]=nums[faster]*nums[faster];
}
sort(nums.begin(),nums.end());
return nums;
}
};