移除0元素
来源:互联网 发布:python 调用sap 编辑:程序博客网 时间:2024/05/17 06:48
283. Move Zeroes
Given an array nums
, write a function to move all 0
's to the end of it while maintaining the relative order of the non-zero elements.
For example, given nums = [0, 1, 0, 3, 12]
, after calling your function, nums
should be [1, 3, 12, 0, 0]
.
(ps:数字部分按照数组原顺序输出,不需要排序)
Note:
- You must do this in-place without making a copy of the array.
- Minimize the total number of operations
public class Solution { public void moveZeroes(int[] nums) { int j = 0; for (int i = 0; i < nums.length; i++) {if (nums[i] != 0) {nums[j] = nums[i];j++;}} for (int i = j; i < nums.length; i++) {nums[i] = 0;} }}
0 0
- 移除0元素
- iterator移除元素
- List移除元素
- 计蒜客 元素移除
- 移除DOM元素
- QVector移除元素
- 元素移除
- 移除元素
- 元素移除
- 计蒜客 -- 元素移除
- 计蒜客 元素移除
- 移除元素方法
- python 元素移除
- JavaScript移除数组元素
- JQuery移除一个元素
- Java List 移除元素
- JAVA List 移除元素
- 计蒜客009-元素移除
- 产品环境中安装Cassandra 3.7
- 基于Windows在VirtualBox部署CentOS 7
- struct和typedef struct
- unity 优化大全
- Binary
- 移除0元素
- Makefile Learing (下)
- ZZULIOJ 1918: G 【二分图匹配】
- 微信内置浏览器私有接口WeixinJSBridge介绍
- HDU 3308 LCIS(线段树)
- 关于数组指针,指针数组,双重数组,二维矩阵,字符串数组,双重字符指针的理解
- 蛇形数组
- ruby 2.1.1 rails 4.2.0 安装gemset 却少 mysql ,command line tool for mac osx
- Can You See The Beauty Of This Photo? Most People Can’t