-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path283. Move Zeroes.py
More file actions
40 lines (36 loc) · 1.03 KB
/
283. Move Zeroes.py
File metadata and controls
40 lines (36 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Solution:
def moveZeroes(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
lenght = len(nums)
currzero = 0
numszero = 0
for x in range(lenght):
if nums[x] == 0:
currzero = x
numszero += 1
elif nums[x] != 0 and numszero > 0:
pos = currzero - numszero + 1
nums[pos] = nums[x]
nums[x] = 0
currzero += 1
# def moveZeroes(nums):
# """
# Do not return anything, modify nums in-place instead.
# """
# lenght = len(nums)
# currzero = 0
# numszero = 0
# for x in range(lenght):
# if nums[x] == 0:
# currzero = x
# numszero += 1
# elif nums[x] != 0 and numszero > 0:
# pos = currzero - numszero + 1
# nums[pos] = nums[x]
# nums[x] = 0
# currzero += 1
# nums = [0, 7, 0, 0, 0, 1]
# moveZeroes(nums)
# print(nums)