> For the complete documentation index, see [llms.txt](https://longxingtan.gitbook.io/mle-interview/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://longxingtan.gitbook.io/mle-interview/01_leetcode/05_stack_queue/1429.-first-unique-number.md).

# \*1429. First Unique Number

<https://leetcode.com/problems/first-unique-number/>

## solution

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

    def showFirstUnique(self) -> int:
        while self.queue and self.counter[self.queue[0]] != 1:
            self.queue.popleft()
        return -1 if not self.queue else self.queue[0]

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

时间复杂度：O()\
空间复杂度：O()
