[Leet Code] Single Number

Input: nums = [2,2,1]
Output: 1
Input: nums = [4,1,2,1,2]
Output: 4
Input: nums = [1]
Output: 1
class Solution(object):
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
answers = []
for i in nums:
if i in answers:
answers.pop(answers.index(i))
else:
answers.append(i)

return answers[0]

--

--

--

Learning, and posting my findings!

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

Create a Lightweight but powerful Docker for Laravel Lumen API

A new way to visualize complex Python objects

Case XX: From thousand to ten millions for 10k

That time I coded 90 hours in one week.

Dart asynchronous programming: Streams

IA for PKM — Definitions, Defined

One container many applications

Fully-working iOS Prototype in 7 Days | DBFF #60

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
Matthew Boyd

Matthew Boyd

Learning, and posting my findings!

More from Medium

[Leet Code] Maximum Number of Words Found in Sentences

Wells Fargo — Software Developer

Last Stone Weight💧

Sliding Window #1: Finding the maximum sum of k consecutive elements in an array