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])

 

posted @ 2020-04-29 10:02  人间烟火地三鲜  阅读(132)  评论(0编辑  收藏  举报