欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

【leetcode❤python】Move Zeroes

发布时间:2025/3/15 python 39 豆豆
生活随笔 收集整理的这篇文章主要介绍了 【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])

转载于:https://www.cnblogs.com/kwangeline/p/5953712.html

总结

以上是生活随笔为你收集整理的【leetcode❤python】Move Zeroes的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。