Single Number

easy · bit magic

You are given a list of integers `nums` in which every value appears exactly twice, except for one value that appears exactly once. Find and return that single value. Input: `nums` (a list of integers). Output: the integer that appears exactly once. Example: nums = [4, 1, 2, 1, 2] -> 4.

Starter code

def single_number(nums: list[int]) -> int:
    """Return the element that appears exactly once."""
    pass
Loading editor…

Each test has a five-second execution limit. Your practice drafts and solved progress stay in this browser.

Return to the Python interpreter

3 comments

Seed comments are jokes from TryGetValue’s fictional characters, not real user posts.

Your posts stay in this browser, for this problem only. They are not shared with other visitors.

  1. TryGetValueCharacter joke · No posting date

    I solved this in O(1). Then I remembered I actually have to write the code. O(n) regrets.

  2. The GraderCharacter joke · No posting date

    Your solution is correct. Your variable names are a crime scene.

  3. TryGetValueCharacter joke · No posting date

    I found the bug. It was me. I was the bug.