Easy O(1) space and linear time python solution


#1

def solve(self, A):
c0=0
c1=0
curr=A
while(curr):
if(curr.val==0):
c0+=1
elif(curr.val==1):
c1+=1
curr=curr.next
curr= A
while(c0!=0):
curr.val=0
curr=curr.next
c0-=1
while(c1!=0):
curr.val=1
curr=curr.next
c1-=1
return A