博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
leetcode283. [Array]Move Zeroes My Submissions Question
阅读量:4221 次
发布时间:2019-05-26

本文共 734 字,大约阅读时间需要 2 分钟。

Total Accepted: 61817 Total Submissions: 141889 Difficulty: Easy

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:

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

class Solution(object):    def moveZeroes(self, nums):        j=0;counts=0        for i in range(len(nums)):            print nums[i]            if nums[i]!=0:                nums[j]=nums[i]                j=j+1            else:                counts=counts+1        for i in range(j,len(nums)):                nums[i]=0

转载地址:http://fzqmi.baihongyu.com/

你可能感兴趣的文章
Netty框架学习之路(一)—— Java网络IO模型
查看>>
如何编写一份优雅的Spring配置文件
查看>>
重学设计模式(一)—— 简单工厂、工厂方法、抽象工厂
查看>>
重学设计模式(二)—— 单例模式
查看>>
Netty框架学习之路(二)—— 一个简单的Netty程序
查看>>
重学设计模式(三)—— 构造器模式
查看>>
Netty框架学习之路(三)—— 初识Netty线程模型
查看>>
重学设计模式(四)—— 原型模式
查看>>
重学设计模式(五)—— 装饰器、适配器、门面和代理
查看>>
Netty框架学习之路(四)—— Channel及相关概念
查看>>
SpringMVC启动过程浅析
查看>>
重学设计模式(六)—— 观察者模式
查看>>
SpringMVC请求处理过程浅析
查看>>
重学设计模式(七)—— 责任链模式
查看>>
Netty框架学习之路(五)—— EventLoop及事件循环机制
查看>>
MyBatis的缓存机制
查看>>
Java中的锁及AQS实现原理
查看>>
MySQL索引及优化
查看>>
MySQL的锁问题
查看>>
Java并发容器及其实现原理
查看>>