parent
e8d1a1a36b
commit
ffe981fb6c
|
|
@ -106,6 +106,7 @@ class Solution {
|
||||||
int index = result.length - 1;
|
int index = result.length - 1;
|
||||||
while (left <= right) {
|
while (left <= right) {
|
||||||
if (nums[left] * nums[left] > nums[right] * nums[right]) {
|
if (nums[left] * nums[left] > nums[right] * nums[right]) {
|
||||||
|
// 正数的相对位置是不变的, 需要调整的是负数平方后的相对位置
|
||||||
result[index--] = nums[left] * nums[left];
|
result[index--] = nums[left] * nums[left];
|
||||||
++left;
|
++left;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue