mycode  77.24%

class Solution(object):
def moveZeroes(self, nums):
"""
:type nums: List[int]
:rtype: None Do not return anything, modify nums in-place instead.
"""
pos = 0
for i in range(len(nums)):
if nums[i] != 0 :
nums[pos] = nums[i]
pos += 1
nums[pos:] = [0]*len(nums[pos:])

参考:

思路类似于

26-Remove Duplicates from Sorted Array

def moveZeros(nums):
j = 0 # 记录非零元素应该换到第几个位置
for i in range(len(nums)):
if nums[i] != 0:
nums[j], nums[i] = nums[i], nums[j]
j += 1
return nums
print(moveZeros([1,0,1,0,3,12]))

leetcode-easy-array-283 move zeros的更多相关文章

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

  2. leetcode 283 Move Zeros; 27 Remove Elements; 26 Remove Duplicated from Sorted Array;

    ,,,,}; //把数组的值赋给vector vector<int> vec(arr, arr+sizeof(arr)/sizeof(int)); 解法一: 时间复杂度O(n) 空间复杂度 ...

  3. LeetCode 283 Move Zeros

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

  4. [LeetCode&Python] Problem 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. [Array]283. Move Zeroes

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

  6. [刷题] 283 Move Zeros

    要求 将所有的0,移动到vector的后面比如; [1,3,0,12,5] -> [1,3,12,5,0] 实现 第一版程序,时间.空间复杂度都是O(n) 1 #include<iostr ...

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

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

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

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

  10. 【leetcode】283. Move Zeroes

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

随机推荐

  1. RabbitMQ入门教程(九):首部交换机Headers

    原文:RabbitMQ入门教程(九):首部交换机Headers 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog ...

  2. Homebrew学习(一)之初认识

    Homebrew Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装.卸载.更新.查看.搜索等很多实用的功能.简单的一条指令,就可以实现包管理,而不用你关心各种依赖和文件路径的情况,会 ...

  3. npm学习(十二)之高级用法

    如何使用距离标记标记包 如何使用双因素身份验证 如何使用安全令牌 如何从CLI更改配置文件设置 理解包和模块

  4. 如何使用前端分页框架bootstrap paginator

    前端分页框架bootstrap paginator用于web前端页面快速实现美观大方的翻页功能.在实现交互良好的页面翻页功能时,往往还需要配合使用后端分页框架pagehelper.pagehelper ...

  5. python 四舍五入进位不准

    python中四舍五入进位不准,自己写了个方法结果: def new_round(_float, _len): ''' 四舍五入保留小数位,如果想实现 0.2 显示为 0.20,可使用 '%.2f' ...

  6. jfinal layui easyexcel 实现文件的上传下载

    jfinal  layui easyexcel  这三样开源技术这里就不多介绍了,自行百度了解吧,他们的组合算是一个很高效又不失美观的操作体验. 操作主要分以下几步: 1.建立jfinal的操作环境, ...

  7. jfinal layui 多选传值问题整理

    使用layui在显示数据表格进行多选的时候遇到的几个问题: 1.增加监听,让你的数据表格可以进行复选. layui.use('table', function(){ var $ = layui.jqu ...

  8. ip - Linux IPv4 协议实现

    SYNOPSIS(总览) #include <sys/socket.h> #include <net/netinet.h> tcp_socket = socket(PF_INE ...

  9. 云主机使用ansible出现秘钥认证问题

    使用ansible的时候,出现如下秘钥失效的问题: root@jumpserver ftp]# ansible web -m ping The authenticity of host 'web-00 ...

  10. web部署命令简单记录

    非 root 用户设置环境变量:在< .bash_profile >中设置 后台运行:nohup dosomething >> log.out & nginx 启动ng ...