LeetCode May Challenge PlayList - • First Bad Version | First Bad Version...
LeetCode 30 Day Challenge PlayList - • Move Zeroes LeetCode | Move Zeroes to...
Given a queue of integers, we need to retrieve the first unique integer in the queue.
Implement the FirstUnique class:
FirstUnique(int[] nums) - Initializes the object with the numbers in the queue.
int showFirstUnique() - Returns the value of the first unique integer of the queue, and returns -1 if there is no such integer.
void add(int value) - Insert value to the queue.
For Example -
Example 1:
FirstUnique firstUnique = new FirstUnique([7,7,7,7,7,7]);
firstUnique.showFirstUnique(); // return -1
firstUnique.add(7); // the queue is now [7,7,7,7,7,7,7]
firstUnique.add(3); // the queue is now [7,7,7,7,7,7,7,3]
firstUnique.add(3); // the queue is now [7,7,7,7,7,7,7,3,3]
firstUnique.add(7); // the queue is now [7,7,7,7,7,7,7,3,3,7]
firstUnique.add(17); // the queue is now [7,7,7,7,7,7,7,3,3,7,17]
firstUnique.showFirstUnique(); // return 17
Example 2:
FirstUnique firstUnique = new FirstUnique([2,3,5]);
firstUnique.showFirstUnique(); // return 2
firstUnique.add(5); // the queue is now [2,3,5,5]
firstUnique.showFirstUnique(); // return 2
firstUnique.add(2); // the queue is now [2,3,5,5,2]
firstUnique.showFirstUnique(); // return 3
firstUnique.add(3); // the queue is now [2,3,5,5,2,3]
firstUnique.showFirstUnique(); // return -1
This problem is the Day 28 of LeetCode 30 Day Challenge Problem.
Website - https://webrewrite.com/
Paypal - https://www.paypal.me/programmingtuto...