Find Single Number
This problem feels like a little puzzle you can solve one step at a time. In Find Single Number, you are trying to work toward the right number by following one clear idea.
Find number that appears only once A good way to think about it is to first understand what goes in, then what rule you must follow, and finally what shape the answer should have.
For example, if the input is nums = [1], the answer is 1. Example with input: nums = [1] Another example is nums = [4,1,2,1,2], which gives 4. Example with input: nums = [4,1,2,1,2]
This is a friendly practice problem, but it still rewards careful reading. The key is understanding the rule clearly and then applying it carefully.
One helpful habit is to say the rule out loud in your own words before you start solving. If you can explain what counts, what changes, and what the final answer should look like, you are already much closer to the right solution.
Example Input & Output
Example with input: nums = [1]
Example with input: nums = [4,1,2,1,2]
Example with input: nums = [2,2,1]
Algorithm Flow

Best Answers
class Solution {
public int single_number(Object nums) {
int[] arr = (int[]) nums;
int result = 0;
for (int num : arr) {
result ^= num;
}
return result;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
