D68 283. Move Zeroes
题目链接
283. Move Zeroes
题目分析
给定一个整数数组,将值为0的元素移动到数组末尾,而不改动其他元素出现的顺序。
思路
计算总共有多少个元素。
再在去0后的元素末尾填充0到计算出的数组长度。
最终代码
<?phpclass Solution { /** * @param Integer[] $nums * @return NULL */ function moveZeroes(&$nums) { $total = count($nums); $nums = array_pad(array_filter($nums),$total,0); return $nums; } }
若觉得本文章对你有用,欢迎用[爱发电](https://afdian.net/@skys215)资助。