
本文共 3379 字,大约阅读时间需要 11 分钟。
������������������������������������������������
���������������������������������������������������������������������������������������������������������������������������
������������
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������
���������������������������������������������������������������������������
������������������������
������������������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������������������������������������������
���������������������������������
���������������������������������������������������������������������������A������������������B������������������B���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������������������C���������������������
struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) { // ������������������������������ if (headA == NULL || headB == NULL) { return NULL; } // ��������������������� int lenA = 0; struct ListNode *currentA = headA; while (currentA != NULL) { lenA++; currentA = currentA->next; } int lenB = 0; struct ListNode *currentB = headB; while (currentB != NULL) { lenB++; currentB = currentB->next; } // ������������������ if (lenA > lenB) { int diff = lenA - lenB; struct ListNode *currentA = headA; while (diff-- > 0 && currentA != NULL) { currentA = currentA->next; } } else if (lenB > lenA) { int diff = lenB - lenA; struct ListNode *currentB = headB; while (diff-- > 0 && currentB != NULL) { currentB = currentB->next; } } // ������������������ struct ListNode *result = NULL; while (headA != NULL && headB != NULL) { if (headA == headB) { result = headA; break; } headA = headA->next; headB = headB->next; } return result;}
������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
