https://leetcode-cn.com/problems/squares-of-a-sorted-array/submissions/
LeetCode 977. 有序数组平方的排序 by Python3
1 class Solution: #等于没做出来,基本上参考的代码随想录的码 2 def sortedSquares(self, nums: List[int]) -> List[int]: 3 l = len(nums) - 1 4 tempNums = [0] * (l + 1) 5 start = 0 6 end = l 7 i = l 8 while start <= end: 9 s = nums[start] ** 2 10 e = nums[end] ** 2 11 if s > e: 12 tempNums[i] = s 13 start += 1 14 else: 15 tempNums[i] = e 16 end -= 1 17 i -= 1 18 return tempNums
虽然已经想到双指针法了,但是却是从中间往两边对比,把问题复杂化,属于没有领悟列表的双指针法思想。
原文:https://www.cnblogs.com/Linanjing/p/15310597.html