160. Intersection of Two Linked Lists

Problem:

思路

Solution (C++):

ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
    using L = ListNode*;
    L a = headA, b = headB;
    while (a) {
        while (b) {
            if (a == b)  return a;
            else b = b->next;
        }
        if (b == NULL) { b = headB; a = a->next; }
    }
    return NULL;
}

性能

Runtime: 932 ms  Memory Usage: 14.8 MB

思路

Solution (C++):


性能

Runtime: ms  Memory Usage: MB

posted @ 2020-03-29 16:32  littledy  阅读(74)  评论(0编辑  收藏  举报