File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments