[Leetcode] 977. 有序数组的平方

题目链接:https://leetcode-cn.com/problems/squares-of-a-sorted-array/
分析:
双指针。
Python

class Solution:
    def sortedSquares(self, A: List[int]) -> List[int]:
        if len(A) == 0:
            return []
        length = len(A) 
        l, r, i = 0, length-1, length-1
        res = [0]*length
        while l <= r:
            left = A[l]**2
            right = A[r]**2
            if left < right:
                res[i] = right
                r -= 1
            else:
                res[i] = left
                l += 1
            i -= 1
        return res
原文地址:https://www.cnblogs.com/zuotongbin/p/13829140.html