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. Matlab无法打开M文件的错误( Undefined function or method 'uiopen' for input arguments of type 'char)

    错误提示: Undefined function or method 'uiopen' for input arguments of type'char 解决方案: 运行命令 restoredefau ...

  2. Bzoj 2346: [Baltic 2011]Lamp dijkstra,堆

    2346: [Baltic 2011]Lamp Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 428  Solved: 179[Submit][Sta ...

  3. 安卓开发无法识别手机原因之一:手机SDK比工程要求的最小SDK低

      创建工程时,设置限制的最小SDK:   如果你手机的内核版本比你工程的设置的最小SDK低,则不显示   来自为知笔记(Wiz)

  4. Sicily1317-Sudoku-位运算暴搜

    最终代码地址:https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1317.c 这题博主刷了1天,不是为了做出来,AC ...

  5. Genotype&&陨石的秘密

    Genotype: Genotype 是一个有限的基因序列.它是由大写的英文字母A-Z组成,不同的字母表示不同种类的基因.一个基因可以分化成为一对新的基因.这种分化被一个定义的规则集合所控制.每个分化 ...

  6. Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法

    在编写Python时,当使用中文输出或注释时运行脚本,会提示错误信息: SyntaxError: Non-ASCII character '\xe5' in file ******* 解决方法: py ...

  7. Yii之权限管理扩展 srbac

    最近在研究 Yii 的权限控制功能,尽管Yii 自身提供了一个简单的权限管理,但是很多时候,我们还是需要对其做一点扩展. 在这里,我向大家推荐一个不错的扩展:SRBAC. 在Yii的官方网站的exte ...

  8. Mysql中查看表的类型InnoDB

    问题描述:   MySQL 数据表主要支持六种类型 ,分别是:BDB.HEAP.ISAM.MERGE.MYISAM.InnoBDB. 这六种又分为两类,一类是“事务安全型”(transaction-s ...

  9. hdoj 5494 Card Game

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5494 题意:首先一个数t代表测试样例组数  然后两个数n,m 代表数列中有n个数  从中取m个数   ...

  10. 【AOS应用基础平台】完好了AOS标签库,和标准标签库完美兼容了

    [金码坊AOS开发平台]今天①完好了AOS标签库,和标准标签库完美兼容了.②新开发了依据子页面动态生成主页面的二级导航菜单功能.#AOS开发平台#