FunctionRacerProblemsRace

Remove Repeated Values

EasyLinked listsPython, JavaScript, TypeScript, Java, C++

The list is not sorted. Keep only the first node of each value and remove every later node with a value you have already seen. Return the head. The list is passed in as head.

Linked lists appear in the tests as the list of their values, like [1,2,3]. Each node is a ListNode with .val and .next; the class is already defined for you.

Example 1

head [3,1,3,2,1]
returns [3,1,2]

The later 3 and later 1 are dropped.

Example 2

head [4,4,4]
returns [4]

Only the first 4 stays.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Linked lists problems