Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 91b14d3

Browse files
committed
added task #977 solution
1 parent d3290fa commit 91b14d3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/task_977/Solution.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package task_977;
2+
3+
import java.util.Arrays;
4+
5+
public class Solution {
6+
7+
public int[] sortedSquares(int[] nums) {
8+
int[] answer = new int[nums.length];
9+
int i = nums.length - 1;
10+
int j = 0;
11+
for (int a = answer.length - 1; a >= 0; a--) {
12+
if (Math.abs(nums[i]) > Math.abs(nums[j])) {
13+
answer[a] = nums[i] * nums[i];
14+
i--;
15+
} else {
16+
answer[a] = nums[j] * nums[j];
17+
j++;
18+
}
19+
}
20+
return answer;
21+
}
22+
23+
}

0 commit comments

Comments
 (0)