forked from SamirPaulb/DSAlgo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create 03. Move all zeroes to end of array.py
- Loading branch information
1 parent
008f1f9
commit 69b63ec
Showing
1 changed file
with
15 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# https://practice.geeksforgeeks.org/problems/move-all-zeroes-to-end-of-array0751/1/# | ||
# https://www.geeksforgeeks.org/move-zeroes-end-array/ | ||
|
||
# Move all zeros to the end | ||
A = [5, 6, 0, 4, 6, 0, 9, 0, 8] | ||
n = len(A) | ||
j = 0 | ||
|
||
for i in range(n): | ||
if A[i] != 0: | ||
A[j], A[i] = A[i], A[j] # Partitioning the array | ||
j += 1 | ||
|
||
print(A) | ||
|