/**
* Definition of ListNode
* class ListNode {
* public:
* int val;
* ListNode *next;
* ListNode(int val) {
* this->val = val;
* this->next = NULL;
* }
* }
*/
class Solution {
public:
/*
* @param head: the first node of linked list.
* @return: An integer
*/
int countNodes(ListNode * head) {
if(head == NULL)
{
return 0;
}
else
{
int i = 0;
for(;head != NULL;head = head->next)
{
i++;
}
return i;
}
}
};
Lintcode 入门-466. 链表节点计数
最新推荐文章于 2022-02-04 20:17:55 发布