[LeetCode][python3]Day28. First Unique Number (30-Day LeetCoding Challenge)

  1. My solution
class FirstUnique:

def __init__(self, nums: List[int]):
self.queue=set()
self.uni=OrderedDict()
for i in nums:
self.add(i)

def showFirstUnique(self) -> int:
return next(iter(self.uni.items()))[0] if self.uni else -1

def add(self, value: int) -> None:
if value not in self.queue:
self.uni[value]=True
self.queue.add(value)
elif value in self.uni:
del self.uni[value]
#print(self.queue,self.uni)
class FirstUnique:

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

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

def add(self, value: int) -> None:
self.c[value] += 1
self.d.append(value)

--

--

--

HI I’m N2I. Now a SWE in Taiwan. Check out more about me in https://nzi2020.blogspot.com/ or contact via email: nayzi9999@gmail.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Zip me baby one more time

JVM Architecture

Semantics Analysis

The first cloning project with the first Collaboration.

KubeCon + CloudNative Con 2018

How Dominos Delivering Pizzas in 10 minutes with AWS ???

Bluehost Reviews — 10 Pros & Cons You Should Know in 2021

Open Source Hackathon Series: An Incubator for Innovation

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
N2I

N2I

HI I’m N2I. Now a SWE in Taiwan. Check out more about me in https://nzi2020.blogspot.com/ or contact via email: nayzi9999@gmail.com

More from Medium

Algorithms Explained Fast and Clear (No BS)

C++ Software developer Interview Q&A — Part 1/2

Introduction to Data Structures: Part 4, Linked Lists

Pascal’s Triangle!