Overwrite the values of zero's and one's :P


#1

/**

  • Definition for singly-linked list.

  • struct ListNode {

  • int val;
    
  • ListNode *next;
    
  • ListNode(int x) : val(x), next(NULL) {}
    
  • };
    /
    ListNode
    Solution::solve(ListNode* A) {

    ListNode* i=NULL;
    //ListNode* j = NULL;
    //ListNode* temp = NULL;
    i = A;
    //j = A->next;
    int one=0,zero=0;
    while(i!= NULL){
    if(i->val==1){one++;}
    else{zero++;}
    i=i->next;
    }
    i=A;
    while(i!=NULL){
    while(zero–){
    i->val=0;
    i=i->next;
    }
    while(one–){
    i->val=1;
    i=i->next;
    }

    }

    return A;

}