注意链表是否为空。
int GetListNodeLen(struct ListNode* l1)
{
if (l1 == NULL)
{
return 0;
}
struct ListNode*p=l1;
int aListLen = 0;
while(p != NULL) //判断当前节点指针是否为空
{
aListLen ++;
p = p->next;
}
return aListLen;
}