Leetcode Problem 1429. First Unique Number

1429. First Unique Number

Leetcode Solutions

Queue and HashMap of Unique-Status

  1. Initialize a queue and a hashmap in the constructor.
  2. For each number in the initial array, add it to the queue and update its count in the hashmap.
  3. In the add method, insert the value into the queue if it's not already present in the hashmap, and update its count in the hashmap.
  4. In the showFirstUnique method, iterate over the queue and return the first number that has a count of one in the hashmap.
  5. If no unique number is found, return -1.
UML Thumbnail

Brute Force

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...