LeetCode报错runtime error:member access within null pointer of type struct ListNode

在for循环中p指针在经过一个循环后P指针位置在NULL,所以在对q指针赋值时是用NULL空地址赋值,所以提示出错。

因此在while循环前加上判断P指针是否为NULL就可以解决。*p=head,head是指向第一个链表数据。

猜你喜欢

转载自blog.csdn.net/qq_40416375/article/details/106130381