해커랭크(HackerRank)
Compare two linked lists
cepiloth
2018. 8. 19. 17:19
반응형
1. 문제
2. 알고리즘
키워드 - 구현, 링크 리스트
3. 코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /* Compare two linked lists A and B Return 1 if they are identical and 0 if they are not. Node is defined as struct Node { int data; struct Node *next; } */ int CompareLists(Node *headA, Node* headB) { // This is a "method-only" submission. // You only need to complete this method if (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 |
반응형