#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].

Note:

  1. You must do this in-place without making a copy of the array.
  2. Minimize the total number of operations.

题解:维护两个下标,index和遍历数组的i

class Solution {
public:
void moveZeroes(vector<int>& nums) {
int index=;
for(int i=;i<nums.size();i++)
{
if(nums[i]!=)
{
swap(nums[index],nums[i]);
index++;
} }
}
};

Leetcode-283 Move Zeroes的更多相关文章

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

  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 -easy

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

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

  5. Java [Leetcode 283]Move Zeroes

    题目描述: Given an array nums, write a function to move all 0's to the end of it while maintaining the r ...

  6. Leetcode 283 Move Zeroes python

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

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

  8. LeetCode 283 Move Zeroes 解题报告

    题目要求 Given an array nums, write a function to move all 0's to the end of it while maintaining the re ...

  9. [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 ...

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

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

随机推荐

  1. mysql时间查看以及定时器相关操作

    1.查看事件 show events select * from mysql.event 2.查看是否开启定时器 0:off:1:on 开启定时器:set global event_scheduler ...

  2. SDK,monkey 浅谈

    最近在工作之余碰到一些手机测试的新手,现在测试手机的基本都是android的系统. 然后在遇到压力测试的时候就开始遇到问题了. 压力测试用什么工具?怎么使用?工具怎么来? 今天遇到两个人都问我SDK是 ...

  3. Asp.net MVC生命周期

    Asp.net应用程序管道处理用户请求时特别强调"时机",对Asp.net生命周期的了解多少直接影响我们写页面和控件的效率.因此在2007年和2008年我在这个话题上各写了一篇文章 ...

  4. Codeforces 714C. Sonya and Queries Tire树

    C. Sonya and Queries time limit per test:1 second memory limit per test: 256 megabytes input:standar ...

  5. android里R.layout.的问题

    今天,在Exlipse里的一个项目在.java文件里写  setContentView(R.layout.activity_problem);时,显示错误,以为是R.java文件里没有对应的activ ...

  6. 20145225《Java程序设计》 2015—2016年学期课程总结

    20145225<Java程序设计> 2015—2016年学期课程总结 读书笔记链接汇总 1.2016年2月25日 <Java程序设计>课程准备之问卷调查 摘要: 一.你对自己 ...

  7. 封装getElementsByClassName()

    function getElementsByClassName(node,classname){             if(node.getElementsByClassName){        ...

  8. 【转】Fiddler的基本介绍

    转:http://kb.cnblogs.com/page/130367/#basic Fiddler的官方网站:  www.fiddler2.com Fiddler的官方帮助:http://docs. ...

  9. emum类(2)

    emum定义如下: public abstract class Enum<E extends Enum<E>>extends Objectimplements Comparab ...

  10. ASP.NET MVC5 与EF6学习系列

    最近学习使用MVC5和EF6,博客园搜索了一番,写下这篇文章记录,以便学习使用. 一.ASP.NET MVC5 网站开发 @洞庭夕照写的博客系列 ASP.NET MVC5 网站开发实践 - 概述 AS ...