LeetCode 977. 有序数组的平方
2019-02-17 23:06
369 查看
给定一个按非递减顺序排序的整数数组
A,返回每个数字的平方组成的新数组,要求也按非递减顺序排序。
示例 1:
输入:[-4,-1,0,3,10] 输出:[0,1,9,16,100]
示例 2:
输入:[-7,-3,2,3,11] 输出:[4,9,9,49,121]
提示:
1 <= A.length <= 10000
-10000 <= A[i] <= 10000
A
已按非递减顺序排序。[code]class Solution: def sortedSquares(self, A): """ :type A: List[int] :rtype: List[int] """ return sorted([i*i for i in A ])
将A中元素遍历出来,然后平方,放进列表,最后对列表进行排序。
相关文章推荐
- Leetcode刷题2-977.有序数组的平方(C++)
- LeetCode977.有序数组的平方(python)
- leetcode刷题思路总结_有序数组的平方
- 【LeetCode】4. Median of Two Sorted Arrays两个有序数组的中位数
- leetcode——Search a 2D Matrix 二维有序数组查找(AC)
- leetcode——Search a 2D Matrix 二维有序数组查找(AC)
- 【算法之美】求解两个有序数组的中位数 — leetcode 4. Median of Two Sorted Arrays
- [LeetCode] 26. Remove Duplicates from Sorted Array 有序数组中去除重复项
- LeetCode 4. Median of Two Sorted Arrays(两个有序数组的中位数)
- leetcode88. 合并两个有序数组
- 【leetcode】Two Sum II - Input array is sorted(输入有序的数组,求两个数的和)
- leetcode:Merge Sorted Array(合并两个有序数组到其中一个数组中)【面试算法题】
- [LeetCode] 88. Merge Sorted Array 合并有序数组
- LeetCode-Remove Duplicates from Sorted Array-从有序数组移除重复-简单逻辑
- LeetCode 88. 合并两个有序数组
- leetcode 4. 移除有序数组中的重复元素 Remove Duplicates from Sorted Array
- leetCode 88. Merge Sorted Array 有序数组
- [LeetCode-34] Search for a Range (寻找有序数组中关键值的索引范围)
- [C++]LeetCode 26: Remove Duplicates from Sorted Array(有序数组去重)
- [LeetCode] 80. Remove Duplicates from Sorted Array II 有序数组中去除重复项 II