Skip to content

Latest commit

 

History

History
51 lines (35 loc) · 1.31 KB

_1429. First Unique Number.md

File metadata and controls

51 lines (35 loc) · 1.31 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : October 26, 2024

Last updated : October 26, 2024


Related Topics : Array, Hash Table, Design, Queue, Data Stream

Acceptance Rate : 55.03 %


Solutions

Python

class FirstUnique:

    def __init__(self, nums: List[int]):
        self.queue = deque(nums)
        self.counter = Counter(nums)

        while self.queue and self.counter[self.queue[0]] > 1 :
            self.queue.popleft()

    def showFirstUnique(self) -> int:
        return -1 if not self.queue else self.queue[0]

    def add(self, value: int) -> None:
        self.counter[value] += 1
        self.queue.append(value)
        while self.queue and self.counter[self.queue[0]] > 1 :
            self.queue.popleft()

# Your FirstUnique object will be instantiated and called as such:
# obj = FirstUnique(nums)
# param_1 = obj.showFirstUnique()
# obj.add(value)