# Leetcode 977. Squares of a Sorted Array ###### tags: `Leetcode(C++)` 題目 : https://leetcode.com/problems/squares-of-a-sorted-array/ 。 想法 : 乘完平方後再排序。 時間複雜度 : O(nlogn)。 程式碼 : ``` class Solution { public: vector<int> sortedSquares(vector<int>& nums) { int l=nums.size(); for(int i=0 ; i<l ; i++){ nums[i]=nums[i]*nums[i]; } sort(nums.begin(),nums.end()); return nums; } }; ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up