393. Remove Duplicates from Sorted List II

MediumLinked ListLinked ListTwo Pointers

Given the head of a sorted linked list, delete all nodes that have duplicate values, leaving only values that appear exactly once in the original list. Return the resulting list as an array.

Input: A sorted array of node values.

Output: Array — values appearing exactly once.

Examples

Example 1
Input: [1,2,3,3,4,4,5]
Output: [1,2,5]
Explanation: 3 and 4 removed entirely.
Example 2
Input: [1,1,1,2,3]
Output: [2,3]
Explanation: All 1s removed.
Example 3
Input: [1,2,3]
Output: [1,2,3]
Explanation: No duplicates.

Constraints

Asked by

BloombergGoogleMicrosoftOracleAppleMeta
Solve this problem in the editor →