提交 2d37207c 编写于 作者: 糖果店的幽灵's avatar 糖果店的幽灵 🥇

Signed-off-by: burebaobao <739891689@qq.com>

上级
# -*- coding: utf-8 -*-
# @project : 代码库
# @author: liwei
# @file: __init__.py.py
# @ide: PyCharm
# @time: 2021/7/25 16:46
# -*- coding: utf-8 -*-
# @project : 代码库
# @author: liwei
# @file: moveZeroes.py
# @ide: PyCharm
# @time: 2021/7/25 16:47
'''
描述:输入一个数组,返回将数组中0放到最后的数组。
分析:我们可以遍历数组,将等于零的放入原位置,设置两个变量分别存储元数组中下标,和j存储非零位置应该的下标,每次遍历到非零时将此时值给j位置的元素且j加1,这样当非零且one不等于j时,即将one位置赋值为0
'''
class Solusion:
def moveZeroes(self,lista):
j = 0
for one in range(0,len(lista)):
if lista[one] != 0:
lista[j] = lista[one]
if one != j:
lista[one] =0
j+=1
return lista
print(Solusion().moveZeroes([0,1,0,3,12]))
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册