Skip to content

Commit 99b6e63

Browse files
authored
Create 0977. Squares of a Sorted Array
1 parent a8f1ee2 commit 99b6e63

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

0977. Squares of a Sorted Array

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/****************************************
2+
977. Squares of a Sorted Array
3+
4+
Difficulty: Easy
5+
6+
Given an array of integers A sorted in non-decreasing order,
7+
return an array of the squares of each number, also in sorted non-decreasing order.
8+
9+
Example 1:
10+
Input: [-4,-1,0,3,10]
11+
Output: [0,1,9,16,100]
12+
13+
Example 2:
14+
Input: [-7,-3,2,3,11]
15+
Output: [4,9,9,49,121]
16+
17+
Note:
18+
1 <= A.length <= 10000
19+
-10000 <= A[i] <= 10000
20+
A is sorted in non-decreasing order.
21+
****************************************/
22+
23+
24+
class Solution {
25+
public int[] sortedSquares(int[] A) {
26+
for (int i = 0; i < A.length; i ++) {
27+
A[i] = A[i] * A[i];
28+
}
29+
30+
Arrays.sort(A);
31+
return A;
32+
}
33+
}

0 commit comments

Comments
 (0)