Sort by

recency

|

1012 Discussions

|

  • + 0 comments
    cur1=llist1
        cur2=llist2
        val1=[]
        val2=[]
        while cur1:
            val1.append(cur1.data)
            cur1=cur1.next
        while cur2:
            val2.append(cur2.data)
            cur2=cur2.next
        if val1==val2:
            return 1
        else:
            return 0
    
  • + 0 comments

    Mi solución en Python 3:

    def compare_lists(llist1, llist2):
        while llist1 and llist2:
            if llist1.data != llist2.data:
                return 0
            llist1= llist1.next
            llist2= llist2.next
        
        if llist1 is None and llist2 is None:
            return  1
        else:
            return  0
    
  • + 1 comment

    Solution using JAVA :

    static boolean compareLists(SinglyLinkedListNode head1, SinglyLinkedListNode head2) {
            while(head1!=null || head2!=null){
                if(head1 == null || head2==null){
                    return false;
                }
                if(head1.data == head2.data){
                    head1 = head1.next;
                    head2 = head2.next;
                }else{
                    return false;
                }
            }
            return true;
        }
    
  • + 0 comments
    def compare_lists(llist1, llist2):
        if llist1 is None and llist2 is None:
            return 1
        elif llist1 is None or llist2 is None:
            return 0
        elif llist1.data == llist2.data:
            
            return compare_lists(llist1.next, llist2.next)
        
        return 0
    
  • + 0 comments
    def compare_lists(llist1, llist2):
        count1 = 0
        count2 = 0
        while llist1 is not None and llist2 is not None:
            if llist1.data == llist2.data:
                count1+=1
                count2+=1
            else:
                return 0
            llist1 =llist1.next
            llist2 = llist2.next
            if ((llist1 is None and llist2 is not None) or (llist1 is not None and llist2 is None)):
                return 0
        if count1 == count2:
            return 1