【leetcode❤python】Move Zeroes
#-*- coding: UTF-8 -*-
#filter()函数可以对序列做过滤处理,就是说可以使用一个自定的函数过滤一个序列,
#把序列的每一项传到自定义的过滤函数里处理,并返回结果做过滤。最终一次性返回过滤后的结果。
class Solution(object):
# def filterDemo(self,nums):
# if nums!=0:
# return nums
def moveZeroes(self, nums):
# pointNum=nums.count(0)
point=0
n=len(nums)
calNum=0
while calNum<n:
print nums[point]
if(nums[point]==0):
nums.append(0)
del nums[point]
print nums
else:point+=1
calNum+=1
print nums
# nums=filter(self.filterDemo,nums)
# nums.extend([0]*pointNum)
# print nums
sol=Solution()
sol.moveZeroes(nums=[0,1,0,3,12])
【leetcode❤python】Move Zeroes的更多相关文章
- 【leetcode❤python】Sum Of Two Number
#-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...
- 【leetcode❤python】172. Factorial Trailing Zeroes
#-*- coding: UTF-8 -*-#给定一个整数N,那么N的阶乘N!末尾有多少个0? 比如:N=10,N!=3628800,N!的末尾有2个0.#所有的尾部的0可以看做都是2*5得来的,所以 ...
- 【leetcode❤python】 1. Two Sum
#-*- coding: UTF-8 -*- #AC源码[意外惊喜,还以为会超时]class Solution(object): def twoSum(self, nums, target): ...
- 【leetcode❤python】 58. Length of Last Word
#-*- coding: UTF-8 -*-#利用strip函数去掉字符串去除空格(其实是去除两边[左边和右边]空格)#利用split分离字符串成列表class Solution(object): ...
- 【leetcode❤python】 8. String to Integer (atoi)
#-*- coding: UTF-8 -*-#需要考虑多种情况#以下几种是可以返回的数值#1.以0开头的字符串,如01201215#2.以正负号开头的字符串,如'+121215':'-1215489' ...
- [leetcode]python 283. Move Zeroes
Given an array nums, write a function to move all 0's to the end of it while maintaining the relativ ...
- 【leetcode❤python】 165. Compare Version Numbers
#-*- coding: UTF-8 -*-class Solution(object): def compareVersion(self, version1, version2): ...
- 【leetcode❤python】 168. Excel Sheet Column Title
class Solution(object): def convertToTitle(self, n): """ :type n: in ...
- 【leetcode❤python】 7. Reverse Integer
#-*- coding: UTF-8 -*-#2147483648#在32位操作系统中,由于是二进制,#其能最大存储的数据是1111111111111111111111111111111.#正因为此, ...
随机推荐
- [Ubuntu] Autostart nginx, php-fpm and mysql in Ubuntu14.04
[nginx] Step 1 Download the shell script wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu ...
- javascript加载顺序
javascript加载顺序 <script type="text/javascript" src="jquery.js"></script& ...
- Angularjs之基本概念梳理(一)
1.Angularjs指令属性ng-app和ng-controller的理解 ng-app指令-标记了AngularJS脚本的作用域,在<html>中添加ng-app属性即说明整个< ...
- 设置Tab键为四个空格
https://my.oschina.net/xunxun10/blog/110074
- oracle 创建表空间用户
1.创建普通表空间和用户 //创建临时表空间create temporary tablespace oa_temptempfile 'D:\app\Administrator\oradata\orcl ...
- IE6不支持CSS的属性选择器
input[type="text"] { width: 50px; } 测试IE6不生效,而IE7以上浏览器则没问题
- 【JQGRID DOCUMENTATION】.学习笔记.5.Form Editing
JqGrid支持为view ,add, edit,delete, search创建一个on the fly的form.这使得Modal Boxes和行内编辑能够在程序用结合.毕竟,行内编辑只能用在已经 ...
- 使用composer构建PHP框架怎么把Redis引入
选择 nrk/predis 作为 Redis 驱动,修改composer.json增加一个 require 项: "predis/predis": "*" 运行 ...
- mysqldump备份过程中都干了些什么
mysqldump备份方便,易读,功能丰富,相信大家都有 使用过这个命令进行备份,但是这个命令在备份的过程中都做了写什么呢,下面打开general_log进行查看: 1.登录mysql命令行客户端: ...
- Android处理图片OOM的若干方法小结 (推荐)
众所周知,每个Android应用程序在运行时都有一定的内存限制,限制大小一般为16MB或24MB(视平台而定).因此在开发应用时需要特别关注自身的内存使用量,而一般最耗内存量的资源,一般是图片.音频文 ...