283MoveZeroes
来源:互联网 发布:公司数据库搭建 编辑:程序博客网 时间:2024/05/01 09: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].
Note:
You must do this in-place without making a copy of the array.
Minimize the total number of operations.
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
void moveZeroes(vector<int>& nums) { /*int temp=0; for(int i=0;i<nums.size();) { if(!nums[i]) { nums.erase(nums.begin()+i); ++temp; } else ++i; } for (int j = 0; j <temp ; ++j) { nums.push_back(0); }*/ for (int i = 0, j = 0; i < nums.size(); i++) if (nums[i]) swap(nums[i], nums[j++]); for(auto num:nums) { cout<<num<<ends; } }
阅读全文
0 0
- 283MoveZeroes
- 283MoveZeroes
- 1st round, 283 moveZeroes
- moveZeroes--JavaScript
- LeetCode moveZeroes
- LeetCode : MoveZeroes
- Java编程题目-14:MoveZeroes
- leetcode中MoveZeroes问题1ms→0ms
- 283
- ocp-283
- seoreZoveM.283
- Leetcode 283
- Leetcode 283
- 283@365
- leetcode-283
- 题目:283 对称排序
- cf 283A
- nyoj,283,对称排序
- #Deep Learning回顾#之LeNet、AlexNet、GoogLeNet、VGG、ResNet
- jquery 地图缩放时禁止父容器滚动条滚动
- sscanf函数用法详解
- hadoop集群中运行中时服役和退役节点
- Spring MVC中Date处理
- 283MoveZeroes
- 【HDU1695】GCD(莫比乌斯反演)
- 虚拟机Ubuntu14.04+MXNET+CPU安装
- c语言实现二叉树常用算法
- 通过C++实现判断点与多边形的关系和两点之间的距离
- 数据结构实验之图论十:判断给定图是否存在合法拓扑序列
- 关于Home Lab的搭建——像使用服务器一样远程管理(三)
- Mybatis之缓存
- maven私服搭建和使用