leetcode 160. 相交链表

思路

代码:

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
        ListNode * a = headA;
        ListNode * b = headB;
        while(a!=b)
        {
            if(a!=NULL)
            {
                a = a->next;
            }
            else
            {
                a = headB;
            }
            if(b!=NULL)
            {
                b=b->next;
            }
            else{
                b=headA;
            }
        }
        return b;

    }
};
以大多数人努力程度之低,根本轮不到去拼天赋~
原文地址:https://www.cnblogs.com/gcter/p/15338710.html