Skip to content

Commit d97bac8

Browse files
refactor 977
1 parent b29a5e9 commit d97bac8

File tree

1 file changed

+9
-28
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+9
-28
lines changed

src/main/java/com/fishercoder/solutions/_977.java

+9-28
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,15 @@
22

33
import java.util.Arrays;
44

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-
*/
245
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+
}
3315
}
34-
}
3516
}

0 commit comments

Comments
 (0)