终于下决心开始刷题了!

选择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. 关于jquery中on绑定click事件在苹果手机失效的问题(巨坑啊)

    用一个div当做了一个按钮来使用. <div class="button"> <div class=" next_button button_left ...

  2. TP中if标签

    if标签 If标签如果php中if语句的作用,if是用于流程控制的. 在ThinkPHP中if标签也是用于流程控制的. If标签的语法格式: <if condition=’条件表达式’> ...

  3. MySQL---索引算法B+/B-树原理(二)

    B+/-Tree原理 B-Tree介绍 B-Tree是一种多路搜索树(并不是二叉的):        1.定义任意非叶子结点最多只有M个儿子:且M>2:        2.根结点的儿子数为[2, ...

  4. 【前端】JS截取字符串常用方法详细整理

    函数:split() 功能:使用一个指定的分隔符把一个字符串分割存储到数组 例子: str=”jpg|bmp|gif|ico|png”; arr=theString.split(”|”); //arr ...

  5. 【.Net】在WinForm中选择本地文件

    相信很多朋友在日常的编程中总会遇到各钟各样的问题,关于在WinForm中选择本地文件就是很多朋友们都认为很难的一个学习.net的难点, 在WebForm中提供了FileUpload控件来供我们选择本地 ...

  6. liunx 用户和用户组的命令

    查看用户列表     /etc/passwd  查看用户组列表 /etc/group 用户和用户组管理 groupadd groups 新增用户组 groupmod -n newgroupsr gro ...

  7. 网站统计IP PV UV实现原理

    网站流量统计可以帮助我们分析网站的访问和广告来访等数据,里面包含很多数据的,比如访问试用的系统,浏览器,ip归属地,访问时间,搜索引擎来源,广告效果等.原来是一样的,这次先实现了PV,UV,IP三个重 ...

  8. word----遇到问题-----word中插入的图片无法左对齐----格式按钮为灰色

    当我们在用word时,有时要插入图片,却发现,插入的图片只在中间位置,不能拖到左边,这时怎么办呢 主要是图层的高低原因导致的不能拖动. 这个时候我们只需要设置一下图片的图层类型即可. 对着图片右键在设 ...

  9. ContestHunter#24-C 逃不掉的路

    Description: 求无向图的必经边 思路:一眼题 将无向图缩成树,然后求两点树上距离 #include<iostream> #include<vector> #incl ...

  10. 【agc017E】Jigsaw

    Portal -->agc017 Description 给你\(n\)块积木,每块积木由三个矩形组成,中间的矩形最高高度为\(h\),左边的矩形高度为\(a_i\)离底边高度为\(c_i\), ...