-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path283.py
31 lines (27 loc) · 793 Bytes
/
283.py
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
#==================================================
#==> Title: move-zeroes
#==> Author: Zhang zhen
#==> Email: hustmatnoble.gmail.com
#==> GitHub: https://github.com/MatNoble
#==> Date: 1/9/2021
#==================================================
"""
https://leetcode-cn.com/problems/move-zeroes/submissions/
"""
class Solution:
def moveZeroes(self, nums):
"""
Do not return anything, modify nums in-place instead.
"""
i, j = 0, 0
while j < len(nums):
if nums[j] != 0:
nums[i], nums[j] = nums[j], nums[i]
i += 1
j += 1
mat = Solution()
nums = [0,1,0,3,12]
nums_ = nums[:]
mat.moveZeroes(nums_)
print(f'before: {nums}')
print(f' after: {nums_}')