136. Single Number
June 24, 2025
04:32 AM
No headings found
Loading content...
No headings found
Problem
Bài toán yêu cầu tìm phần tử duy nhất xuất hiện một lần trong mảng số nguyên, trong khi các phần tử khác đều xuất hiện đúng hai lần.
Approach - XOR
Solution
1function singleNumber(nums: number[]): number {
2 let res = 0
3 for(const num of nums) res = res ^ num
4 return res
5};