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. 2013 ACM区域赛长沙 A Alice’s Print Service HDU 4791

    题意:就是一个打印分段收费政策,印的越多,单张价格越低,输入需要印刷的数量,求最小印刷费用一个细节就是,比当前还小的状态可能是最后几个. #include<stdio.h> #includ ...

  2. Java--创建线程及常用方法

    继承java.lang.Thread类--Thread类代表线程类  它的常用方法如下: static Thread currentThread():返回当前正在运行的线程对象的引用. static ...

  3. hyperVisor

    当前主要的hyperVisors:VMware vSphere.微软Hyper-V.Citrix XenServer .IBM PowerVM.Red Hat Enterprise Virtuliza ...

  4. android 使用intent传递参数实现乘法计算

    主界面上是两个EditText和一个按钮.用于输入两个数字参数. calcute.xml: <?xml version="1.0" encoding="utf-8& ...

  5. java synchronized与volatile的区别

    java线程同步有两个特性,一个是可见性,一个是有序性.在解释这两个概念之前,先说下两个重要的概念,主内存(main memory)和工作内存(working memory),线 程之间数据的交互不是 ...

  6. 配置好maven后,设置tomcat:run运行程序

    1.要在intellij idea使用maven,同样是先要配置maven的路径,不过intellij idea已经集成maven插件了,省去了安装的麻烦 2.创建maven web项目 点击fini ...

  7. 用高德地图API 通过详细地址获得经纬度

    http://cloud.sinyway.com/Service/amap.html http://restapi.amap.com/v3/geocode/geo?key=xxxxxxxxxxxxxx ...

  8. 利用WinDriver开发PCI设备驱动程序

    摘要 WinDriver是Jungo公司出版的一个设备驱动程序开发组件,它可以大大加速PCI设备驱动程序的开发.作者在实际的项目中采用了WinDriver来开发设备驱动程序,取得了相当好的运行效果.从 ...

  9. oracle本月、上月、去年同月第一天最后一天

    select trunc(sysdate, 'month') 本月第一天,        trunc(last_day(sysdate)) 本月最后一天,        trunc(add_month ...

  10. C# - 类型

    C#是一门使用OOP技术的编程语言(Object Oriented Programming 面向对象编程)面向对象最重要的特性就是接口.继承.多态 C#中所有的事物都可以看做是一个对象 对象由类型来创 ...