From 69b63ece63dcbded5048c59a10823d2f78703177 Mon Sep 17 00:00:00 2001 From: Samir Paul <77569653+SamirPaul1@users.noreply.github.com> Date: Fri, 8 Jul 2022 23:15:44 +0530 Subject: [PATCH] Create 03. Move all zeroes to end of array.py --- 18_Array/03. Move all zeroes to end of array.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 18_Array/03. Move all zeroes to end of array.py diff --git a/18_Array/03. Move all zeroes to end of array.py b/18_Array/03. Move all zeroes to end of array.py new file mode 100644 index 00000000..4f1a0514 --- /dev/null +++ b/18_Array/03. Move all zeroes to end of array.py @@ -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) +