leetcode283: Move Zeroes
来源:互联网 发布:轻量级linux安装详解 编辑:程序博客网 时间:2024/06/05 21:14
要求:对于给定的数组,要去把0全部移到数组尾部,非零项保持大小顺序不变。 例如:
a=[1,2,3,0,0,4,0,5]结果:
a=[1,2,3,4,5,0,0,0]注意:使用两个变量作为指针,如果是非零项就直接按顺序放入原数组中。最后补齐0就可以了
public void moveZeroes(int[] nums) { int l = nums.length;int j = 0;int count = 0;for (int i = 0; i < l; i++) {if (nums[i] != 0) {nums[j++] = nums[i];} elsecount++;}for (int k = l - count; k < l; k++)nums[k] = 0; }
0 0
- leetcode283 : Move Zeroes
- [LeetCode283]Move Zeroes
- leetcode283 Move Zeroes
- LeetCode283. Move Zeroes
- leetcode283: Move Zeroes
- Leetcode283. Move Zeroes
- leetcode283~Move Zeroes
- leetcode283. Move Zeroes
- LeetCode283. Move Zeroes 解答
- leetcode283. [Array]Move Zeroes My Submissions Question
- LeetCode283——Move Zeroes我的解法
- leetcode283---Move Zeroes(把0移到数组后面)
- Leetcode283 Move Zeros
- LeetCode283——Move Zeroes(将0移动到数组最后面)
- Move Zeroes
- Move Zeroes
- Move Zeroes
- Move Zeroes
- Linux线程的创建和使用
- 旋转矩阵
- hdu1242Rescue
- 欢迎使用CSDN-markdown编辑器
- js的三种继承方法
- leetcode283: Move Zeroes
- 强大的request
- 2.14 ProgressDialog 进度条对话框的使用
- JavaScript Break 和 Continue 语句
- linux的nohup命令的用法。在应用Unix/Linux时,我们一般想让某个程序在后台运行,于是我们将常会用 & 在程序结尾来让程序自动运行。比如我们要运行mysql在后台: /usr/local
- 9. 视图
- selenium的进阶1
- c语言链表操作
- Servlet处理HTTP请求(2)