-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path283. Move Zeros.py
More file actions
30 lines (28 loc) · 825 Bytes
/
283. Move Zeros.py
File metadata and controls
30 lines (28 loc) · 825 Bytes
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
class Solution:
def moveZeroes(self, nums):
"""
:type nums: List[int]
:rtype: void Do not return anything, modify nums in-place instead.
"""
fst0 = 0
fst1 = 0
while (fst1 < len(nums)) & (fst0 < len(nums)):
if (nums[fst1] == 0):
fst1 = fst1 + 1
elif (nums[fst0] != 0):
fst0 = fst0 + 1
elif(fst0<fst1):
nums[fst1], nums[fst0] = nums[fst0], nums[fst1]
fst0 = fst0 + 1
fst1 = fst1 + 1
else:
fst1=fst1+1
return nums
TestCase = [1,0]
ExpectOutput = [1,0]
solu = Solution()#先对类初始化,才能进行调用
temp = solu.moveZeroes(TestCase)
if (temp == ExpectOutput):
print('right')
else:
print('wrong')