leetcode刷题,总结,记录,备忘 283
来源:互联网 发布:网络评选投票 编辑:程序博客网 时间:2024/06/11 14:25
leetcode283Move 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.
这题是道简单题,就不多做解释了。
class Solution {public: void moveZeroes(vector<int>& nums) { int count = 0; for (vector<int>::iterator it = nums.begin(); it != nums.end();) { if (*it == 0) { nums.erase(it); count++; } else { ++it; } } for (int i = 0; i < count; ++i) { nums.push_back(0); } }};
0 0
- leetcode刷题,总结,记录,备忘 283
- leetcode刷题。总结,记录,备忘 104
- leetcode刷题。总结,记录,备忘 100
- leetcode刷题。总结,记录,备忘 191
- leetcode刷题。总结,记录,备忘。168
- leetcode刷题, 总结,记录,备忘 171
- leetcode刷题 ,总结,记录,备忘。144
- leetcode刷题,总结,记录, 备忘 141
- leetcode刷题,总结,记录,备忘。116
- leetcode刷题,总结,记录,备忘。96
- leetcode刷题。记录,总结,备忘。217
- leetcode 刷题, 总结,记录,备忘 35
- leetcode刷题,总结,记录,备忘 226
- leetcode刷题,总结,记录,备忘 169
- leetcode刷题,总结,记录,备忘137
- leetcode刷题,总结,记录,备忘83
- leetcode刷题,总结,记录,备忘70
- leetcode刷题,总结,记录,备忘 108
- io流
- 禁止浏览器缓存- make sure web page is not cached
- 实现ListView的 分页加载,通过点击按钮实现
- HDU 4252A Famous City
- 删除字符串中连续字符
- leetcode刷题,总结,记录,备忘 283
- Effective C++ —— 别让异常逃离析构函数
- Struts、hibernate、Spring 官网下载步骤
- C# 反射实例 一
- iOS中Bitcode的介绍及配置
- SQL Server数据库
- Python 标准库——collections(下)
- 关于ListView触摸事件和点击Item事件冲突解决方法
- [速报酱]速报酱团队第一周