283. Move 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].

题目大意:

给一个数组,将值为0的元素放置到最后,其他元素相对位置不变。

解题方法:

排序题,修改插入排序的判断条件就可以了

注意事项:

C++代码:

 class Solution {
public:
void moveZeroes(vector<int>& nums) //仿插入排序
{
int j,tmp;
for(int p=;p<nums.size();p++)
{
tmp=nums[p];
for(j=p;j>&&tmp!=&&nums[j-]==;j--)
{
swap(nums[j],nums[j-]);
}
nums[j]=tmp;
}
}
};

283. Move Zeroes(C++)的更多相关文章

  1. leetcode:283. Move Zeroes(Java)解答

    转载请注明出处:z_zhaojun的博客 原文地址:http://blog.csdn.net/u012975705/article/details/50493772 题目地址:https://leet ...

  2. LeetCode 283. Move Zeroes (移动零)

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

  3. LeetCode 283 Move Zeroes(移动全部的零元素)

    翻译 给定一个数字数组.写一个方法将全部的"0"移动到数组尾部.同一时候保持其余非零元素的相对位置不变. 比如,给定nums = [0, 1, 0, 3, 12],在调用你的函数之 ...

  4. 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 ...

  5. 【leetcode】283. Move Zeroes

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

  6. 283. Move Zeroes【easy】

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

  7. LN : leetcode 283 Move Zeroes

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

  8. 283. Move Zeroes - LeetCode

    Question 283. Move Zeroes Solution 题目大意:将0移到最后 思路: 1. 数组复制 2. 不用数组复制 Java实现: 数组复制 public void moveZe ...

  9. leetcode 283. Move Zeroes -easy

    题目链接:https://leetcode.com/problems/move-zeroes/ 题目内容: Given an array nums, write a function to move ...

随机推荐

  1. 解析XML文件示例

    项目中要解析Xml文件,于是在工程里找了下前人写例子. 1,SAX(基于事件,效率高,使用声明加载什么). public class MVCConfig { private static MVCCon ...

  2. EJB (not bound)

    问题: 在代码实在找不到错误的情况下,仍然报:XXXX not bound 问题产生过程: 通过下图方式创建的项目:EJBTest2_1 勾选下面两项,即可生成:EJBTest2_1EJB 和 EJB ...

  3. usaco 奶牛集会 && 奶牛抗议

    奶牛集会 Description 约翰家的N头奶牛每年都会参加“哞哞大会” .哞哞大会是世界奶牛界的盛事.集会上 的活动很多,比如堆干草,跨栅栏,摸牛仔的屁股等等.当然,哞哞大叫肯定也包括在内. 奶牛 ...

  4. Using Live555 to Stream Live Video from an IP camera connected to an H264 encoder

    http://stackoverflow.com/questions/27279161/using-live555-to-stream-live-video-from-an-ip-camera-con ...

  5. Verilog HDL模块的结构

    一个设计是由一个个模块(module)构成的.一个模块的设计如下: 1.模块内容是嵌在module 和endmodule两个语句之间.每个模块实现特定的功能,模块可进行层次的嵌套,因此可以将大型的数字 ...

  6. javascript字符串基本方法

    1)auchor anchor() 方法用于创建 HTML 锚. var txt="Hello world!" document.write(txt.anchor("my ...

  7. ZooKeeper监控

    http://jm-blog.aliapp.com/?p=1450 在公司内部,有不少应用已经强依赖zookeeper,zookeeper的工作状态直接影响它们的正常工作.目前开源世界中暂没有一个比较 ...

  8. 【转】cocos2d-x游戏开发(八)各类构造器

    欢迎转载:http://blog.csdn.net/fylz1125/article/details/8521997 这篇写cocos2d-x的构造器. cocos2d-x引入自动释放机制后,创建的对 ...

  9. kindle

    http://www.mindmap8.com/Kindle_Paperwhite/20130726266.html http://blog.csdn.net/felomeng/article/det ...

  10. PureMVC(JS版)源码解析(十二):Facade类

    MVC设计模式的核心元素在PureMVC中体现为Model类.View类和Controller类.为了简化程序开发,PureMVC应用Facade模式.    Facade是Model\View\Co ...