We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
解法一:使用双指针法
代码如下:
var getIntersectionNode = function(headA, headB) { let pA = headA; let pB = headB; // 遍历两个链表,一直到链表尾部,即为 null // 将链表A指向链表B头部,链表B指向链表A头部,重新遍历,第二次如果相交,即为交叉点。若没有,则不相交 while (pB !== pA) { // 最后如果都没有相交,则同时为 null,结束 pA = pA === null ? headB : pA.next; pB = pB === null ? headA : pB.next; } return pA; };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
160. 相交链表
思路
解法一:使用双指针法
代码如下:
复杂度分析
The text was updated successfully, but these errors were encountered: