X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Basic Accuracy: 69.83% Submissions: 100k+ Points: 1

Given a singly linked list. The task is to find the length of the linked list, where length is defined as the number of nodes in the linked list.

Example 1:

Input:
Output: 5
Explanation: Count of nodes in the
linked list is 5, which is its length.


Example 2:

Input:
Output: 7
Explanation: Count of nodes in the
linked list is 7. Hence, the output
is 7.

Your task is to complete the given function getCount(), which takes a head reference as an argument and should return the length of the linked list.

Expected Time Complexity : O(N)
Expected Auxilliary Space : O(1)

Constraints:
1 <= N <= 105
1 <= value <= 103