less than 1 minute read

Given a singly linked list node, return its length. The linked list has fields next and val.

Constraints

  • n ≤ 100,000 where n is the number of nodes in node

https://binarysearch.com/problems/Length-of-a-Linked-List

Examples

Example 1

Input

  • node =

Output

  • answer = 3

Explanation

This linked list has 3 nodes.

Example 2

Input

  • node =

Output

  • answer = 2

Explanation

This linked list has 2 nodes.

Solution

Leave a comment