O(N) and O(1) simple solution


#1
ListNode* Solution::solve(ListNode* A) 
{
    ListNode* head = A,*t1 = NULL;
    while(head)
    {
        if(head->val == 1 && !t1)
        {
            t1 = head;
        }
        if(t1 && head->val == 0)
        {
            swap(t1->val,head->val);
            t1 = t1->next;
        }
        head = head->next;
    }
    return A;
}