美文网首页
[Leetcode]977. Squares of a Sort

[Leetcode]977. Squares of a Sort

作者: 麻薯团子子 | 来源:发表于2019-02-09 15:22 被阅读0次

一、问题链接:
https://leetcode.com/problems/squares-of-a-sorted-array/
二、思路:
1、给定一个数组,目前是非递减排序,给平方之后的结构按照非递减顺序排列
2、遍历数组先平方,然后再排序

三、编码:
JAVA版本:
class Solution {
public int[] sortedSquares(int[] A) {
for (int a = 0; a < A.length; a++) {
A[a] = A[a] * A[a];
}
Arrays.sort(A);
return A;
}
}

相关文章

网友评论

      本文标题:[Leetcode]977. Squares of a Sort

      本文链接:https://www.haomeiwen.com/subject/bctzsqtx.html