llllmz

导航

977. 有序数组的平方

sort 一下

class Solution {
public:
    vector<int> sortedSquares(vector<int>& nums) {
        vector<int> ret;
        for(int num : nums){
            ret.push_back(pow(num, 2));
        }
        sort(ret.begin(), ret.end());
        return ret;
    }
};

posted on 2024-09-08 16:47  神奇的萝卜丝  阅读(12)  评论(0)    收藏  举报