
Single Number II (medium)
Problem Statement
Given an array of integers nums where each element appears three times, and one element appears exactly once, return the single element.
Note: You must solve the problem with linear runtime complexity and use only constant extra space.
Examples
- Example 1:
- Input: nums =
[4, 3, 3, 3] - Expected Output:
4 - Justification:
4is the only number that appears once, while3appears three times.
- Input: nums =
- Example 2:
- Input: nums =
[99, 1, 99, 99, 2, 2, 2] - Expected Output:
1 - Justification:
1appears exactly once whereas99and2each appear three times.
- Input: nums =
- Example 3:
- Input: nums =
[0, 7, 2, 7, 2, 7, -1, 2, -1, -1] - Expected Output:
0 - Justification:
0is the unique number appearing once, while7,2and-1appear three times.
- Input: nums =
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory