977. Squares of a Sorted Arrayphp
本题比较简单。对给定数组的每个数字的平方。并对结果进行排序。数组
遍历每个元素,相乘自身。塞入新数组。函数
再用sort函数排序。.net
<?php class Solution { function sortedSquares($A) { $z = []; foreach($A as $b){ $z[] = $b*$b; } sort($z); return $z; } }
若以为本文章对你有用,欢迎用爱发电资助。code