|
2 | 2 |
|
3 | 3 | import java.util.Arrays;
|
4 | 4 |
|
5 |
| -/** |
6 |
| - * 977. Squares of a Sorted Array |
7 |
| - * |
8 |
| - * Given an array of integers A sorted in non-decreasing order, return an array of the squares of each number, also in sorted non-decreasing order. |
9 |
| - * |
10 |
| - * Example 1: |
11 |
| - * Input: [-4,-1,0,3,10] |
12 |
| - * Output: [0,1,9,16,100] |
13 |
| - * |
14 |
| - * Example 2: |
15 |
| - * Input: [-7,-3,2,3,11] |
16 |
| - * Output: [4,9,9,49,121] |
17 |
| - * |
18 |
| - * |
19 |
| - * Note: |
20 |
| - * 1 <= A.length <= 10000 |
21 |
| - * -10000 <= A[i] <= 10000 |
22 |
| - * A is sorted in non-decreasing order. |
23 |
| - */ |
24 | 5 | public class _977 {
|
25 |
| - public static class Solution1 { |
26 |
| - public int[] sortedSquares(int[] A) { |
27 |
| - int[] result = new int[A.length]; |
28 |
| - for (int i = 0; i < A.length; i++) { |
29 |
| - result[i] = (int) Math.pow(A[i], 2); |
30 |
| - } |
31 |
| - Arrays.sort(result); |
32 |
| - return result; |
| 6 | + public static class Solution1 { |
| 7 | + public int[] sortedSquares(int[] A) { |
| 8 | + int[] result = new int[A.length]; |
| 9 | + for (int i = 0; i < A.length; i++) { |
| 10 | + result[i] = (int) Math.pow(A[i], 2); |
| 11 | + } |
| 12 | + Arrays.sort(result); |
| 13 | + return result; |
| 14 | + } |
33 | 15 | }
|
34 |
| - } |
35 | 16 | }
|
0 commit comments