给出 1->3->5
, 返回 3
.
以上是LintCode上的样例
int countNodes(ListNode * head)
{
int n = 0;
for(ListNode *p = head;p != NULL;p = p->next)
{
n++;
}
return n;
}
};
给出 1->3->5
, 返回 3
.
以上是LintCode上的样例
int countNodes(ListNode * head)
{
int n = 0;
for(ListNode *p = head;p != NULL;p = p->next)
{
n++;
}
return n;
}
};