终于下决心开始刷题了!

选择LintCode而不是LeetCode主要是因为LintCode操作更顺手,希望能够坚持下去。

还是循序渐进吧,数据结构和算法的东西很久没碰都很生疏了,先找找感觉。

这是一刷,解法很有可能是很笨的解法,代码风格也可能不够好,二刷会直接在下面更新。

Thu, Sep 20, 2016

题目描述:

给一个数组 nums 写一个函数将 0 移动到数组的最后面,非零元素保持原数组的顺序

注意事项

1.必须在原数组上操作
2.最小化操作数

 
思路:
直接删除0元素,在后面补上。
 
代码:
 void moveZeroes(vector<int>& nums)
{
int i = ;
int n = nums.size();
for (vector<int>::iterator iter = nums.begin(); iter != nums.end();)
{
if (++i == n) break;
if (*iter == )
{
nums.erase(iter);
nums.push_back();
}
else
{
++iter;
}
}
}

LintCode 539: Move Zeroes的更多相关文章

  1. [LintCode] Move Zeroes 移动零

    Given an array nums, write a function to move all 0's to the end of it while maintaining the relativ ...

  2. LeetCode:Move Zeroes

    LeetCode:Move Zeroes [问题再现] Given an array nums, write a function to move all 0's to the end of it w ...

  3. 【5_283】Move Zeroes

    终于碰到一道水题,睡觉去~ Move Zeroes Total Accepted: 37369 Total Submissions: 88383 Difficulty: Easy Given an a ...

  4. Leetcode-283 Move Zeroes

    #283.   Move Zeroes Given an array nums, write a function to move all 0's to the end of it while mai ...

  5. 283. Move Zeroes(C++)

    283. Move Zeroes Given an array nums, write a function to move all 0's to the end of it while mainta ...

  6. leetcode之旅(7)-Move Zeroes

    Move Zeroes 题目描述: Given an array nums, write a function to move all 0's to the end of it while maint ...

  7. LeetCode Javascript实现 283. Move Zeroes 349. Intersection of Two Arrays 237. Delete Node in a Linked List

    283. Move Zeroes var moveZeroes = function(nums) { var num1=0,num2=1; while(num1!=num2){ nums.forEac ...

  8. 【leetcode】283. Move Zeroes

    problem 283. Move Zeroes solution 先把非零元素移到数组前面,其余补零即可. class Solution { public: void moveZeroes(vect ...

  9. 【leetcode】Move Zeroes

    Move Zeroes 题目: Given an array nums, write a function to move all 0‘s to the end of it while maintai ...

随机推荐

  1. lintcode-463-整数排序

    463-整数排序 给一组整数,按照升序排序,使用选择排序,冒泡排序,插入排序或者任何 O(n2) 的排序算法. 样例 对于数组 [3, 2, 1, 4, 5], 排序后为:[1, 2, 3, 4, 5 ...

  2. http://deepdish.io/2015/04/28/creating-lmdb-in-python/

    http://deepdish.io/2015/04/28/creating-lmdb-in-python/

  3. Docker 安装与常用命令介绍

    docker的镜像文件作用就是:提供container运行的文件系统层级关系(基于AUFS实现),所依赖的库文件.已经配置文件等等. 安装docker yum install -y docker 启动 ...

  4. QMap使用

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:QMap使用     本文地址:https://www.techieliang.com/201 ...

  5. Node.js系列——(1)安装配置与基本使用

    1.安装 进入下载地址 小编下载的是msi文件,下一步下一步傻瓜式安装. 打印个hello看看: 2.REPL 全称Read Eval Print Loop,即交互式解释器,可以执行读取.执行.打印. ...

  6. 初探Android动画之门

    原文地址:http://www.cnblogs.com/kross/p/3376451.html 最近自学了下动画的相关知识,总结为今天的文章,希望对大家有帮助. Android中的动画大致分为三种: ...

  7. GLSL反转矩阵inverse

    低版本 vertex shader 可以使用,通常用来反转TBN矩阵,但是计算量很大. 代码来自 OpenGL Mathematics (GLM) mat4 inverse_mat4(mat4 m) ...

  8. C++解析(12):初始化列表与对象构造顺序、析构顺序

    0.目录 1.类成员的初始化 2.类中的const成员 3.对象的构造顺序 3.1 局部对象的构造顺序 3.2 堆对象的构造顺序 3.3 全局对象的构造顺序 4.对象的析构顺序 5.小结 1.类成员的 ...

  9. 分布式文件系统服务器FastDFS

    1. 什么是FastDFS FastDFS 是用 c 语言编写的一款开源的分布式文件系统.FastDFS 为互联网量身定制, 充分考虑了冗余备份.负载均衡.线性扩容等机制,并注重高可用.高性能等指标, ...

  10. Python3 字典 fromkeys()方法

     Python3 字典 描述 Python 字典 fromkeys() 函数用于创建一个新字典,以序列seq中元素做字典的键,value为字典所有键对应的初始值. 语法 fromkeys()方法语法: ...