Skip to content

Commit 886e4f3

Browse files
committed
Add 977-SquaresOfASortedArray.cpp
1 parent 8a18ea3 commit 886e4f3

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution {
2+
public:
3+
vector<int> sortedSquares(vector<int>& nums) {
4+
int n = nums.size(); std::vector<int> sq(n, 0);
5+
for(int p = 0; p < n; p++){sq[p] = nums[p] * nums[p];}
6+
sort(sq.begin(), sq.end());
7+
return sq;
8+
}
9+
}

0 commit comments

Comments
 (0)