mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
@ -98,6 +98,26 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
Java:
|
Java:
|
||||||
|
```Java
|
||||||
|
class Solution {
|
||||||
|
public int[] sortedSquares(int[] nums) {
|
||||||
|
int right = nums.length - 1;
|
||||||
|
int left = 0;
|
||||||
|
int[] result = new int[nums.length];
|
||||||
|
int index = result.length - 1;
|
||||||
|
while (left <= right) {
|
||||||
|
if (nums[left] * nums[left] > nums[right] * nums[right]) {
|
||||||
|
result[index--] = nums[left] * nums[left];
|
||||||
|
++left;
|
||||||
|
} else {
|
||||||
|
result[index--] = nums[right] * nums[right];
|
||||||
|
--right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Python:
|
Python:
|
||||||
```Python
|
```Python
|
||||||
|
Reference in New Issue
Block a user