-
Compare two linked lists해커랭크(HackerRank) 2018. 8. 19. 17:19반응형
1. 문제
2. 알고리즘
키워드 - 구현, 링크 리스트
3. 코드
123456789101112131415161718192021/*Compare two linked lists A and BReturn 1 if they are identical and 0 if they are not.Node is defined asstruct Node{int data;struct Node *next;}*/int CompareLists(Node *headA, Node* headB){// This is a "method-only" submission.// You only need to complete this methodif (headA == NULL && headB == NULL) {return 1;} else if (headA == NULL || headB == NULL) {return 0;}return (headA->data == headB->data) && CompareLists(headA->next, headB->next);}cs 반응형'해커랭크(HackerRank)' 카테고리의 다른 글
Print in Reverse (0) 2018.08.19 Reverse a linked list (0) 2018.08.19 Insert a node at a specific position in a linked list (0) 2018.08.19 Counting Valleys (0) 2018.08.19 CamelCase (0) 2018.08.19