릿코드(LEETCODE)
136. Single Number
cepiloth
2020. 2. 13. 11:45
반응형
class Solution {
public:
int singleNumber(vector<int>& nums) {
int sol=0;
for(int i=0; i<nums.size(); i++) {
sol = sol ^ nums[i];
}
return sol;
}
};
https://leetcode.com/problems/single-number
1 회만 선언된 숫자를 출력하는 문제
논리식 중 xor 을 사용하여서 간편하게 풀 수 있다.
반응형