/**
* 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;
}
}
};