BudiBadu Logo
00:00

Find Single Number

Array Easy 0 views

You are given a non-empty array of integers in which every element appears exactly twice, except for one unique element that appears only once. Your task is to find that single number and return it. The array can contain both positive and negative integers, but there will always be exactly one number that does not repeat.

Imagine a collection of identical objects where one item is slightly different from the others. While all duplicates cancel each other out, that one special element stands alone. This problem tests your ability to detect uniqueness within repetition, a concept that appears frequently in data validation, error checking, and real-world analytics.

The challenge lies in recognizing the outlier efficiently without altering the array’s structure or using additional heavy memory. If the array contains only one element, that element itself is the single number. The order of numbers does not matter; what matters is identifying the only value without a pair.

Example 1:

Input: nums = [2,2,1]
Output: 1

Example 2:

Input: nums = [4,1,2,1,2]
Output: 4

Example 3:

Input: nums = [1]
Output: 1

Related Problems

No related problems found

Comments (0)

Join the Discussion

Share your thoughts, ask questions, or help others with this problem.

BudiBadu Logo

Find Single Number

Array Easy 0 views

You are given a non-empty array of integers in which every element appears exactly twice, except for one unique element that appears only once. Your task is to find that single number and return it. The array can contain both positive and negative integers, but there will always be exactly one number that does not repeat.

Imagine a collection of identical objects where one item is slightly different from the others. While all duplicates cancel each other out, that one special element stands alone. This problem tests your ability to detect uniqueness within repetition, a concept that appears frequently in data validation, error checking, and real-world analytics.

The challenge lies in recognizing the outlier efficiently without altering the array’s structure or using additional heavy memory. If the array contains only one element, that element itself is the single number. The order of numbers does not matter; what matters is identifying the only value without a pair.

Example 1:

Input: nums = [2,2,1]
Output: 1

Example 2:

Input: nums = [4,1,2,1,2]
Output: 4

Example 3:

Input: nums = [1]
Output: 1

00:00
Loading editor...
Test Results

Run your code to see test results

Click the Submit button to execute your solution

Related Problems

No related problems found

Comments (0)

Join the Discussion

Share your thoughts, ask questions, or help others with this problem.