Skip to content

Commit

Permalink
我的解法 似乎很慢
Browse files Browse the repository at this point in the history
  • Loading branch information
rinwf committed Sep 29, 2018
1 parent 94738fd commit 7100edd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lc283. Move Zeroes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution(object):
def moveZeroes(self, nums):
"""
:type nums: List[int]
:rtype: void Do not return anything, modify nums in-place instead.
"""

idx1 = 0
while idx1 != len(nums):
while nums[idx1] != 0 and idx1 != len(nums) - 1:
idx1 += 1
idx2 = idx1 + 1
while idx2 != len(nums) and nums[idx2] == 0:
idx2 += 1
if idx2 == len(nums):
return
nums[idx1], nums[idx2] = nums[idx2], nums[idx1]


nums = [0, 1, 0, 3, 12]
s = Solution()

print(s.moveZeroes(nums))

0 comments on commit 7100edd

Please sign in to comment.