b*n
2 楼
还有一种做法,可以把两个链表的长度先求出来,这样就知道长度的差
然后再从头开始遍历一遍就行了
然后再从头开始遍历一遍就行了
h*c
3 楼
Another solution: virtually concatenate two linked list
ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
if (!headA || !headB)
return NULL;
ListNode *currA = headA, *currB = headB;
while (currA != currB) {
currA = (currA) ? currA->next : headB;
currB = (currB) ? currB->next : headA;
}
return currA;
}
ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
if (!headA || !headB)
return NULL;
ListNode *currA = headA, *currB = headB;
while (currA != currB) {
currA = (currA) ? currA->next : headB;
currB = (currB) ? currB->next : headA;
}
return currA;
}
相关阅读
微软的senior software engineer怎么样?onsite完求祝福~ebay的面试谁有经验啊? new grad software engineer同时和多个猎头联系好不好?zynga现在还送员工去vegas玩吗?请教class设计和system design题的资料请教图论面试题新公司H1B transfer批准了,在原公司期间能回国么?请教G家onsite一道题问道题,找到电话按键能组成的所有的词M家电面大公司不cover律师费的?接受了postdoc offer, 有公司on-site interview怎么办?刚换工作, 简历还没更新,又要面试。。。A家白板interview失败大家都做哪些online judge?是先申请opt再去找工作还是找到工作了再申请opt?烧香拜佛求bless 下周三个onsite求Offer建议 M,B,ALinux 的困惑。