Length of a Linked List
Given a singly linked list node
, return its length. The linked list has fields next
and val
.
Constraints
n ≤ 100,000
wheren
is the number of nodes innode
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.
Leave a comment