码迷,mamicode.com
首页 > 编程语言 > 详细

977. 有序数组的平方

时间:2020-04-29 10:50:17      阅读:66      评论:0      收藏:0      [点我收藏+]

标签:有序   alt   app   数组   png   ima   microsoft   ros   代码   

技术图片

 

 技术图片

 

 技术图片

 

 技术图片

 

 

代码一:

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

 

977. 有序数组的平方

标签:有序   alt   app   数组   png   ima   microsoft   ros   代码   

原文地址:https://www.cnblogs.com/panweiwei/p/12800285.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!