본문 바로가기
Programming/Data Structure

[Hackerrank] CompareTwoLinkedLists

by 읽고 쓰는 개발자 2020. 12. 2.

https://www.hackerrank.com/challenges/compare-two-linked-lists/problem

 

Compare two linked lists | HackerRank

Compare the data in two linked lists node by node to see if the lists contain identical data.

www.hackerrank.com

package exam.complete;


//https://www.hackerrank.com/challenges/compare-two-linked-lists/problem

import exam.SinglyLinkedListNode;

public class CompareTwoLinkedLists {

    static boolean compareLists(SinglyLinkedListNode head1, SinglyLinkedListNode head2) {
        if(head1.data != head2.data) return false;
        if(head1.next == null && head2.next == null) return true;
        if(head1.next == null || head2.next == null) return false;

        return compareLists(head1.next, head2.next);
    }
}

'Programming > Data Structure' 카테고리의 다른 글

[Hackerrank] FindMergePointofTwoLists  (0) 2020.12.02
[Hackerrank] DeleteNode  (0) 2020.12.02
[Hackerrank] BalancedBrackets  (0) 2020.12.02
[Hackerrank] reverseArray  (0) 2020.12.02
[Hackerrank] MaximumElement  (0) 2020.12.02