Loading...
Loading...
Loading...
Items are stored in a linked list. Given a target number, print the position (counting from 0) of its first occurrence, or -1 if it is not in the list.
Example 1
Input
4 9 7 9 9
Output
1
Example 2
Input
4 9 7 5
Output
-1
Try the problem first. Open one hint at a time.
Walk the nodes and keep a counter of the position.
A while ... else can print -1 when the loop ends without a match.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor