mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
0977. 有序数组的平方
添加Java注释
This commit is contained in:
@ -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 {
|
||||||
|
Reference in New Issue
Block a user