[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.

How to start a DevOps transformation

Ansible ad hoc commands with example

Sending Mail using Jenkins Plugin (Linux based)

How to make something with Swift Playgrounds

Running Windows 11 on the VMWare Player

Medium Post on Agile

Coming soon — Build a Zapier integration on Orangescrum

Tutorial: Scrape 100 Headlines in Seconds with 23 Lines of Python

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

Leetcode — Isomorphic Strings — Easy

Trapping Rainwater Problem: Three different approaches (brute to optimized)

raining gif

[Leet Code] Maximum Number of Words Found in Sentences

An Introduction to Linked Lists