반응형
https://leetcode.com/problems/single-number/
모든 수를 xor 연산해주면, single number만 남게 됩니다.
class Solution {
public:
int singleNumber(vector<int>& nums) {
int res = 0;
for(int num : nums) res ^= num;
return res;
}
};
반응형
'Algorithm' 카테고리의 다른 글
LeetCode 1608. Special Array With X Elements Greater Than or Equal X (0) | 2024.06.09 |
---|---|
LeetCode 1442. Count Triplets That Can Form Two Arrays of Equal XOR (1) | 2024.06.09 |
LeetCode 1002. Find Common Characters (0) | 2024.06.08 |
LeetCode 260. Single Number III (1) | 2024.06.08 |
LeetCode 3110. Score of a String (1) | 2024.06.08 |