Skip to content

Commit

Permalink
Create 03. Move all zeroes to end of array.py
Browse files Browse the repository at this point in the history
  • Loading branch information
SamirPaulb committed Jul 8, 2022
1 parent 008f1f9 commit 69b63ec
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 18_Array/03. Move all zeroes to end of array.py
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)

0 comments on commit 69b63ec

Please sign in to comment.