LeetCode 977. 有序数组的平方

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

给定一个按非递减顺序排序的整数数组 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 已按非递减顺序排序。

1 class Solution {
2     public int[] sortedSquares(int[] A) {
3         for(int i=0;i<A.length;i++){
4             A[i]=A[i]*A[i];
5         }
6         Arrays.sort(A);
7         return A;
8     }
9 }
原文地址:https://www.cnblogs.com/wydxry/p/11594966.html