终于下决心开始刷题了!

选择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. ORACLE公司传奇历史

    ORACLE公司传奇 ORACLE公司之起源 很难想象,ORACLE 公司的这一段传奇居然要从 IBM 公司开始. 1970年的6月,IBM 公司的研究员埃德加·考特 (Edgar Frank Cod ...

  2. WebSphere应用服务器内存泄漏探测与诊断工具选择最佳实践

    内存泄漏是比较常见的一种应用程序性能问题,一旦发生,则系统的可用内存和性能持续下降:最终将导致内存不足(OutOfMemory),系统彻底宕掉,不能响应任何请求,其危害相当严重.同时,Java堆(He ...

  3. find . -name file -exec echo abc > {} \; fail

    find . -name file -exec echo abc > {} \; fail 应该改用: find . -name file -exec bash -c 'echo abc > ...

  4. CentOS7 修改yum源为阿里云

    1,登陆root帐号 2,cd /etc/yum.repo.d 3,mv CentOS-Base.repo CentOS-Base.repo.bak4,wget http://mirrors.aliy ...

  5. 使用java程序模拟页面发送http的post请求

    在web应用程序中,一般都是通过页面发送http的post请求,但也可以使用java程序来模拟页面发送请求,代码如下: import java.io.BufferedReader; import ja ...

  6. C# SqlCommand和SqlDataAdapter的区别

    SqlCommand和SqlDataAdapter的区别 SqlCommand对应DateReader   SqlDataAdapter对应DataSet   SqlCommand的执行效率比较高,但 ...

  7. C#使用 SharpSSH

    准备试一把监控Linux机器 . 附件如下 :http://files.cnblogs.com/files/lclblog/Tamir.SharpSsh.zip

  8. MachineLearning ---- lesson 2 Linear Regression with One Variable

    Linear Regression with One Variable model Representation 以上篇博文中的房价预测为例,从图中依次来看,m表示训练集的大小,此处即房价样本数量:x ...

  9. 多线程---handlerthread

    当我们需要工作线程来操作的时候,很多时候会有同步问题,UI更新问题. Handle机制就是为了解决这个问题而产生的. android允许每个线程都有自己的消息队列,同时也可以是主线程消息队列. 但是很 ...

  10. jmeter链接多台负载机报错

    遇到常见的问题: 1.在Controller端上控制某台机器Run,提示“Bad call to remote host” 解决方案:检查被控制机器上的jmeter-server有没有启动,或者JMe ...