一:题目 二:上码 /*** 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* node1 = headA;ListNode* node2 = headB;int size1 = 0;int size2 = 0;while (node1 != NULL) {node1 = node1->next;size1++;}while (node2 != NULL) {node2 = node2->next;size2++;}ListNode* cur1 = headA;ListNode* cur2 = headB;if (size2 > size1) {swap(size1,size2);swap(cur1,cur2);}int len = size1 - size2;while (len--) {cur1 = cur1->next;}while (cur1 != NULL && cur2 != NULL) {if (cur1 == cur2) {return cur1;}cur1 = cur1->next;cur2 = cur2->next;}return NULL;} };