-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path136.cpp
More file actions
34 lines (24 loc) · 663 Bytes
/
136.cpp
File metadata and controls
34 lines (24 loc) · 663 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// 136. Single Number - https://leetcode.com/problems/single-number
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
int singleNumber(vector<int>& nums) {
int missing_number = 0;
for (const int &num : nums) {
missing_number ^= num;
}
return missing_number;
}
};
int main() {
ios::sync_with_stdio(false);
Solution solution;
vector<int> input = {1, 2, 3, 4, 1, 2, 3};
assert(solution.singleNumber(input) == 4);
input = {1, 1, 2};
assert(solution.singleNumber(input) == 2);
input = {100};
assert(solution.singleNumber(input) == 100);
return 0;
}