977. 有序数组的平方

 

 

 

代码一:

 1 class Solution(object):
 2     def sortedSquares(self, A):
 3         """
 4         :type A: List[int]
 5         :rtype: List[int]
 6         """
 7         ans=[]
 8         for i in range(len(A)):
 9             ans.append(A[i]*A[i])
10         return sorted(ans)

代码二:

1 class Solution(object):
2     def sortedSquares(self, A):
3         """
4         :type A: List[int]
5         :rtype: List[int]
6         """
7         return sorted([i**2 for i in A])
原文地址:https://www.cnblogs.com/panweiwei/p/12800285.html