【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.#正因为此, ...
随机推荐
- 前端单页应用SEO解决方案
在这里只会提到Google的解决方案,日后再补充百度的解决方案 我们经常使用的单页都是#!来做应用的前端路由,因为这个在多个版本浏览器上有很好的兼容性 当Google发现URL里有#!符号,Googl ...
- Inside TSQL Querying - Chapter 3. Query Tuning
Tuning Methodology When dealing with performance problems, database professionals tend to focus on t ...
- linux设备驱动归纳总结(三):4.ioctl的实现【转】
本文转载自:http://blog.chinaunix.net/uid-25014876-id-59419.html linux设备驱动归纳总结(三):4.ioctl的实现 一.ioctl的简介: 虽 ...
- java中OutputStream字节流与字符流InputStreamReader 每一种基本IO流BufferedOutputStream,FileInputStream,FileOutputStream,BufferedInputStream,BufferedReader,BufferedWriter,FileInputStream,FileReader,FileWriter,InputStr
BufferedOutputStream,FileInputStream,FileOutputStream,BufferedInputStream,BufferedReader,BufferedWri ...
- java代码实现rabbitMQ请求
1.下载rabbitMQ的客户端,下载地址 http://www.rabbitmq.com/download.html
- ecshop微信支付(0923更新)商户支付密钥key的生成与设置
ECSHOP 微信支付(0923更新)商户支付密钥key的生成与设置 说明:新版微信支付,用户必须授权登录才能支付.需要商家自己设置商户号支付密钥. 申请微信支付手机版部分时需要填写的配置接口地址: ...
- C++ 关键字 explicit, export, mutable
转自 explicit 如果A类有某个构造函数的单个输入参数,是B类(包括基本数据类型)的对象或引用,则C++的编译器会在需要A类形参的函数调用中,自动调用该构造函数,将B类实参隐式地转换为A类实参. ...
- 完整学习git二 git 暂存区
1 git log 命令查看提交日志信息 git log --pretty-fuller #详细查看 git log --stat #查看每次提交的文件变更 git log --pretty-onli ...
- git学习相关资料
入门还是廖大师的博客. 搭建git服务器: http://blog.csdn.net/code_style/article/details/38764203
- 进程外session
进程外session A SqlServer 1.管理员身份运行cmd 2.更换目录 cd c:\Windows\Microsoft.NET\Framework\v4.0.30319> 3. ...