Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd97bac8

Browse files
refactor 977
1 parentb29a5e9 commitd97bac8

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

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,15 @@
22

33
importjava.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
publicclass_977 {
25-
publicstaticclassSolution1 {
26-
publicint[]sortedSquares(int[]A) {
27-
int[]result =newint[A.length];
28-
for (inti =0;i <A.length;i++) {
29-
result[i] = (int)Math.pow(A[i],2);
30-
}
31-
Arrays.sort(result);
32-
returnresult;
6+
publicstaticclassSolution1 {
7+
publicint[]sortedSquares(int[]A) {
8+
int[]result =newint[A.length];
9+
for (inti =0;i <A.length;i++) {
10+
result[i] = (int)Math.pow(A[i],2);
11+
}
12+
Arrays.sort(result);
13+
returnresult;
14+
}
3315
}
34-
}
3516
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp