mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
添加 面试题02.07.链表相交.md JavaScript语言解法的注释
This commit is contained in:
@ -224,12 +224,14 @@ var getIntersectionNode = function(headA, headB) {
|
||||
lenA = getListLen(headA),
|
||||
lenB = getListLen(headB);
|
||||
if(lenA < lenB) {
|
||||
// 下面交换变量注意加 “分号” ,两个数组交换变量在同一个作用域下时
|
||||
// 如果不加分号,下面两条代码等同于一条代码: [curA, curB] = [lenB, lenA]
|
||||
[curA, curB] = [curB, curA];
|
||||
[lenA, lenB] = [lenB, lenA];
|
||||
}
|
||||
let i = lenA - lenB;
|
||||
while(i-- > 0) {
|
||||
curA = curA.next
|
||||
curA = curA.next;
|
||||
}
|
||||
while(curA && curA !== curB) {
|
||||
curA = curA.next;
|
||||
|
Reference in New Issue
Block a user