终于下决心开始刷题了!

选择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-81-数据流中位数

    81-数据流中位数 数字是不断进入数组的,在每次添加一个新的数进入数组的同时返回当前新数组的中位数. 说明 中位数的定义: 中位数是排序后数组的中间值,如果有数组中有n个数,则中位数为A[(n-1)/ ...

  2. 【UNIX环境编程、操作系统】孤儿进程和僵尸进程

    基本概念: 在类UNIX系统中,僵尸进程是指完成执行(通过exit系统调用,或运行时发生致命错误或收到终止信号所致)但在操作系统的进程表中仍然有一个进程表表项(进程控制块PCB),处于"终止 ...

  3. BZOJ 1799 同类分布(数位DP)

    给出a,b,求出[a,b]中各位数字之和能整除原数的数的个数.1<=a<=b<=1e18. 注意到各位数字之和最大是153.考虑枚举这个东西.那么需要统计的是[0,a-1]和[0,b ...

  4. 洛谷P1345 [USACO5.4]奶牛的电信(最小割)

    题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,...,a(c),且a1与a2相 ...

  5. ans_rproxy 说明

    ans_rproxy 说明 网络IP资源分配 Windows2008R2:        IP: 172.16.204.50/24        Gateway: 172.16.204.1      ...

  6. 【刷题】清橙 A1295 necklace

    试题来源 清华大学2011年百名信息学优秀高中学子夏令营 问题描述 有人打算送给你一条宝石项链,包含了N颗五颜六色(一共有M种颜色)的宝石.因为本问题中你只关心每个宝石的颜色,而且项链现在两头还没有接 ...

  7. bzoj1016: [JSOI2008]最小生成树计数(kruskal+dfs)

    一直以为这题要martix-tree,实际上因为有相同权值的边不大于10条于是dfs就好了... 先用kruskal求出每种权值的边要选的次数num,然后对于每种权值的边2^num暴搜一下选择的情况算 ...

  8. 使用 nginx 代理 tomcat 服务器

    server { listen 80; server_name wechat-jsp.local; root /usr/local/Cellar/tomcat/9.0.5/libexec/webapp ...

  9. Rabbitmq -- rpc

    一.前言 MQ本身是基于异步的消息处理,前面的示例中所有的生产者(P)将消息发送到RabbitMQ后不会知道消费者(C)处理成功或者失败(甚至连有没有消费者来处理这条消息都不知道).但实际的应用场景中 ...

  10. python基础5--模块

    模块 一.模块简介 模块是一个包含有定义的函数和变量的文件,其后缀名是.py.Python的强大之处在于他有非常丰富和强大的标准库和第三方库,几乎你想实现的任何功能都有相应的Python库支持. 标准 ...