leetcode283 Move Zeroes
2016-03-05 11:08
393 查看
283. Move Zeroes
Total Accepted:61066 Total Submissions:
140284 Difficulty: Easy
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,
numsshould be
[1, 3, 12, 0, 0].
Note:
You must do this in-place without making a copy of the array.
Minimize the total number of operations.
class Solution { public: void moveZeroes(vector<int>& nums) { vector<int>::iterator it, end; end = nums.end(); for (it = nums.begin(); it != end;) { if (*it == 0) { nums.erase(it); nums.push_back(0); --end; continue; } ++it; } } };
相关文章推荐
- Odoo 8.0深入浅出开发教程(八) Odoo开发之请假模块第二谈
- RSA证书生成******可用 需有RSAEncryptor.h/.m文件
- dede观看总结自己总结
- Encoding
- 使用Eclipse自带的Axis1插件生成WSDL文件
- 包装类、object、单例模式、final、抽象类
- ARM-Linux移植之(三)——init进程启动流程分析
- 启动httpd报错
- IDEA15使用maven编译scala和java
- 51nod 1085 背包问题
- 并查集之畅通工程
- Java中生成随机数
- Iterm 2 配色, 有颜色的MAC终端
- 简单粗暴-说说STL中vector的实现原理
- DataBase -- SQL INNER JOIN
- 存储过程生成复杂的随机编号
- IDEA15使用maven编译scala和java
- ARM-Linux内核移植之(二)——Linux2.6.22内核移植
- Linux内核中断和异常分析(中)
- Linux内核中断和异常分析(中)