C++ O(n) & O(1) solution


#1
`ListNode* head = A;
 while(A && A->val == 0 ) A = A->next;
 ListNode* trav = A;
 int tmp;
while(trav){
if(trav->val == 0){
    tmp = A->val;
    A->val = 0;
    A = A->next;
    trav->val = tmp;
}
 trav = trav->next;
}
return head;  `