Dashboard Temp Share Shortlinks Frames API

HTMLify

day16.py
Views: 4 | Author: prakhardoneria
1
2
3
4
5
6
7
8
9
class Solution:
    def pushZerosToEnd(self, arr):
        count = 0  # Pointer for the position of the next non-zero element
        
        for i in range(len(arr)):
            # If current element is non-zero, swap it with the element at count
            if arr[i] != 0:
                arr[i], arr[count] = arr[count], arr[i]
                count += 1