less than 1 minute read

Given a list of integers nums, find all duplicate numbers and delete their last occurrences.

Constraints

  • 0 ≤ n ≤ 100,000 where n is the length of nums

https://binarysearch.com/problems/Remove-Last-Duplicate-Entries

Examples

Example 1

Input

  • nums = [1, 1, 1, 2, 2, 2, 3, 3, 3]

Output

  • answer = [1, 1, 2, 2, 3, 3]

Example 2

Input

  • nums = [1, 3, 4, 1, 3, 5]

Output

  • answer = [1, 3, 4, 5]

Solution

Leave a comment