We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 253bddc commit 8452d5fCopy full SHA for 8452d5f
problems/0977.有序数组的平方.md
@@ -178,6 +178,24 @@ class Solution:
178
return sorted(x*x for x in nums)
179
```
180
181
+```Python
182
+(版本四) 双指针+ 反转列表
183
+class Solution:
184
+ def sortedSquares(self, nums: List[int]) -> List[int]:
185
+ #根据list的先进排序在先原则
186
+ #将nums的平方按从大到小的顺序添加进新的list
187
+ #最后反转list
188
+ new_list = []
189
+ left, right = 0 , len(nums) -1
190
+ while left <= right:
191
+ if abs(nums[left]) <= abs(nums[right]):
192
+ new_list.append(nums[right] ** 2)
193
+ right -= 1
194
+ else:
195
+ new_list.append(nums[left] ** 2)
196
+ left += 1
197
+ return new_list[::-1]
198
+
199
### Go:
200
201
```Go
0 commit comments