Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 662 |

@arpitsatnalika | 629 |

@code_it_ | 591 |

@prakharxyz | 583 |

@tujhekya | 542 |

@Rahul Jadhav 1 | 458 |

@sivanandh03 | 448 |

@satyam0460 | 429 |

@iamronak | 424 |

@imnm | 424 |

@18eumc107 | 421 |

Complete Leaderboard |

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:LinkedList: 1->2->3->4->5Output:5Explanation:Count of nodes in the linked list is 5, which is its length.

**Example 2:**

Input:LinkedList: 2->4->6->7->5->1->0Output:7Explanation:Count of nodes in the linked list is 7. Hence, the output is 7.

**Your Task:**

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 <= 10^{5}

1 <= value <= 10^{3}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Count nodes of linked list

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.