Simple Python3 solution in few steps

programming
Tags: #<Tag:0x00007f182c0f82f0>

#1

def solve(self, A):

    count = [0,0]
    
    ptr = A
    
    while ptr!=None:
        count[ptr.val]+=1
        ptr = ptr.next
    
    i = 0
    
    ptr = A
    
    while ptr!=None:
        if count[i] == 0:
            i+=1
        else:
            ptr.val = i
            count[i]-=1
            ptr = ptr.next
    
    return A