Easy · Linked Lists

Find node

Given the head of a singly linked list and a value val, return the first node whose value equals val (the node itself, so the list reads on from it), or null if no node matches.

Examples

Example 1

[3,1,4,1,5] find 4

Output: node[2] = 4

Example 2

[2,7,8] find 9

Output: nil

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Linked Lists problems