https://leetcode.com/problems/intersection-of-two-linked-lists/
回傳當2個鏈結串列值相同的節點。
當2個連結串列都不為空時,判斷2個節點是否相同,相同時則直接回傳,不同時節點則直接移到下一個節點,而當某一個節點為空時將回傳另一個的節點。
struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) {
if (headA == NULL || headB == NULL) return NULL;
struct ListNode * listA = headA, *listB = headB;
while (listA != NULL && listB != NULL) {
if (listA == listB) return listA;
listA = listA->next;
listB = listB->next;
if (listA == listB) return listA;
if (listA == NULL) listA = headB;
if (listB == NULL) listB = headA;
}
return listA;
}
var getIntersectionNode = function(headA, headB) {
if (headA == null || headB == null) return null;
var listA = headA, listB = headB;
while (listA != null && listB != null) {
if (listA == listB) return listA;
listA = listA.next;
listB = listB.next;
if (listA == listB) return listA;
if (listA == null) listA = headB;
if (listB == null) listB = headA;
}
return listA;
};
https://github.com/SIAOYUCHEN/leetcode
https://ithelp.ithome.com.tw/users/20100009/ironman/2500
https://ithelp.ithome.com.tw/users/20113393/ironman/2169
https://ithelp.ithome.com.tw/users/20107480/ironman/2435
https://ithelp.ithome.com.tw/users/20107195/ironman/2382
https://ithelp.ithome.com.tw/users/20119871/ironman/2210
https://ithelp.ithome.com.tw/users/20106426/ironman/2136
When your ability still can't reach your goals, then you should get down to learn.
當你的能力還駕馭不了你的目標時,那你就應該沉下心來學習歷練