Skip to content

Commit 28b959a

Browse files
committed
Added Python solution for "Move Zeroes"
1 parent 386efab commit 28b959a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Python/Move Zeroes.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
"""
6+
Time: O(n)
7+
Memory: O(1)
8+
"""
9+
10+
def moveZeroes(self, nums: List[int]) -> None:
11+
last_non_zero = 0
12+
for cur, num in enumerate(nums):
13+
if num != 0:
14+
nums[cur], nums[last_non_zero] = nums[last_non_zero], num
15+
last_non_zero += 1
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)