【Leetcode_总结】977. 有序数组的平方 - python

Q:

给定一个按非递减顺序排序的整数数组 A,返回每个数字的平方组成的新数组,要求也按非递减顺序排序。

 

示例 1:

输入:[-4,-1,0,3,10]
输出:[0,1,9,16,100]

示例 2:

输入:[-7,-3,2,3,11]
输出:[4,9,9,49,121]

链接:https://leetcode-cn.com/problems/squares-of-a-sorted-array/description/

思路:水一个水一个

代码:

class Solution:
    def sortedSquares(self, A):
        """
        :type A: List[int]
        :rtype: List[int]
        """
        res = [a*a for a in A]
        res.sort()
        return res

【Leetcode_总结】977. 有序数组的平方 - python