We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 37f28e3 commit c79d468Copy full SHA for c79d468
Move_Zeroes/EfficientSolution.py
@@ -0,0 +1,20 @@
1
+##==================================
2
+## Leetcode
3
+## Student: Vandit Jyotindra Gajjar
4
+## Year: 2020
5
+## Problem: 283
6
+## Problem Name: Move Zeroes
7
+##===================================
8
+#Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.
9
+#
10
+#Example:
11
12
+#Input: [0,1,0,3,12]
13
+#Output: [1,3,12,0,0]
14
+class Solution:
15
+ def moveZeroes(self, nums):
16
+ index = 0 #Initialize index
17
+ for i in range(len(nums)): #Loop through nums
18
+ if nums[i] != 0: #Condition-check: if nums[i] is not equal to zero.
19
+ nums[index], nums[i] = nums[i], nums[index] #Swap the values so that zero will go at the end of list.
20
+ index += 1 #Increase index by one
0 commit comments