본문 바로가기

Problem Solving/리트코드(leetcode)

Single Number

class Solution {
public:
    int singleNumber(vector<int>& nums) {
        int answer = nums[0];
        for(int i = 1; i < nums.size(); i++) {
            answer = answer^nums[i];
        }
        return answer;
    }
};

'Problem Solving > 리트코드(leetcode)' 카테고리의 다른 글

Add Digits  (0) 2022.01.16
Summary Ranges  (0) 2022.01.16
Count Primes  (0) 2022.01.16
[Leetcode/C++] 66. Plus One  (0) 2022.01.16
Pascal's Triangle  (0) 2022.01.16