![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/3ad1716ccd515f5715ab5a55f6b98faa.png)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/06b0272ff4639e18a7899a35299a99ad.png)
class Solution:
def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode:
global null
null=''
head1=headA
head2=headB
while head1!=head2:
if head1:
head1=head1.next
else:
head1=headB
if head2:
head2=head2.next
else:
head2=headA
return head1
public class Solution {
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
if(headA==null||headB==null)
{
return null;
}
ListNode head1=headA;
ListNode head2=headB;
while(head1!=head2){
if(head1!=null){
head1=head1.next;
}else{
head1=headB;
}
if(head2!=null){
head2=head2.next;
}else{
head2=headA;
}
}
return head1;
}
}
struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) {
if(headA==NULL||headB==NULL)
{
return NULL;
}
struct ListNode *head1=headA;
struct ListNode *head2=headB;
while(head1!=head2){
if(head1!=NULL){
head1=head1->next;
}else{
head1=headB;
}
if(head2!=NULL){
head2=head2->next;
}else{
head2=headA;
}
}
return head1;
}