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. qt使用QWT注意事项

    当继承某个QWT类时,有是使用O_OBJECT弘会出现问题 切记在工程文件里别忘了添加这一句 DEFINES+=QWT_DLL

  2. servlet和Struts2的线程安全性对比

    1.>在servlet中,定义成员变量是不安全的,,因为,每次请求操作的是该同一个成员变量,,会出现线程不安全的问题. 2.>而在struts2中,在Action中定义成员变量是安全的,, ...

  3. 微信小程序自定义字体及自定义图标问题说明

    自定义图标及自定义字体,一直是很多小程序开发者的心病,其实本站是很多解决方案的,为了集中起来,方便直接跳过此坑,我特别做了这次针对字体及字体图标的跳坑: 相关文章:微信小程序添加并使用外部字体(成功添 ...

  4. Delphi 标识符

  5. Big Data(八)MapReduce的搭建和初步使用

    ---恢复内容开始--- 回顾: 1.最终开发MR的计算程序 2.hadoop 2.x 出现了一个yarn:资源管理>>MR没有后台场服务 yarn模型:container 容器,里面会运 ...

  6. Luogu P2619 [国家集训队2]Tree I 凸优化,wqs二分

    新学的科技.设\(f(x)\)为选\(x\)条白色边的时候的最小生成树权值和,那么可以猜到它应该是一个下凸函数的形式. 如图,图中\(x\)坐标表示选的白色边条数,\(y\)坐标表示获得的权值,那么我 ...

  7. 曝郭盛华公司30万美元收购Acn.ai域名,揭秘人工智能布局下的巨头们

    据域名投资人曝料,郭盛华公司已经提前拿下.ai短域名 Acn.ai,目前域名已经设置跳转到东联科技的官网.都说域名越短越值钱,而且搜索引擎都喜欢更短的域名,例如京东更换的域名“jd.com”交易价格约 ...

  8. autogen.sh 的使用

    在linux下面的大型工程很多都是makefile管理的,但是随着工程越来越大,makefile编写又成了一个大工程,这个时候出现了两个比较流行的工具,cmake和configure,configur ...

  9. vue导航菜单动态展示

    地址:https://blog.csdn.net/qq_31126175/article/details/81875468      

  10. CMDB架构需求实现

    CMDB资产管理部分实现 需求 1.存储所有IT资产信息 2.数据可手动添加 3.硬件信息可自动收集 4.硬件信息可自动变更 5.可对其他系统灵活开放API 6.API接口安全认证 立业之本:定义表结 ...