Skip to content

Commit 6e7e8c6

Browse files
solves move zeroes in python
1 parent fb67b56 commit 6e7e8c6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@
8484
| 268 | [Missing Number](https://leetcode.com/problems/missing-number) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MissingNumber.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/missing_number.py) |
8585
| 270 | 🔒 [Closest Binary Search Tree Value](https://leetcode.com/problems/closest-binary-search-tree-value) | Easy | |
8686
| 276 | 🔒 [Paint Fence](https://leetcode.com/problems/paint-fence) | Easy | |
87-
| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FirstBadVersion.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_bad_version.py)|
88-
| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MoveZeros.java) |
87+
| 278 | [First Bad Version](https://leetcode.com/problems/first-bad-version) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/FirstBadVersion.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_bad_version.py) |
88+
| 283 | [Move Zeroes](https://leetcode.com/problems/move-zeroes) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/MoveZeros.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/move_zeroes.py) |
8989
| 290 | [Word Pattern](https://leetcode.com/problems/word-pattern) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/WordPattern.java) |
9090
| 292 | [Nim Game](https://leetcode.com/problems/nim-game) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/NimGame.java) |
9191
| 293 | [Flip Game](https://leetcode.com/problems/flip-game) | Easy | |

python/move_zeroes.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def moveZeroes(self, nums: List[int]) -> None:
6+
if len(nums) == 1:
7+
return
8+
i, j = 0, 1
9+
while True:
10+
while i < len(nums) and nums[i] != 0:
11+
i += 1
12+
while j < len(nums) and (nums[j] == 0 or j < i):
13+
j += 1
14+
if i >= len(nums) or j >= len(nums):
15+
break
16+
nums[i], nums[j] = nums[j], 0

0 commit comments

Comments
 (0)