day 8: 136-single-number

This commit is contained in:
Kaushik Narayan R 2023-10-04 12:19:30 -07:00
parent 32366c1e21
commit df64aaced5
3 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,9 @@
#include "soln.hpp"
int main() {
vector<int> nums = {1,2,3,4,4,3,1};
int answer = 2;
Solution soln;
cout << "Found single number correctly? " << soln.test(nums, answer) << endl;
return 0;
}

View File

@ -0,0 +1,15 @@
#include "soln.hpp"
int Solution::singleNumber(vector<int> &nums)
{
int uniq = 0;
for (int num : nums)
{
uniq ^= num;
}
return uniq;
}
bool Solution::test(vector<int>& nums, int answer) {
return singleNumber(nums) == answer;
}

View File

@ -0,0 +1,9 @@
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
int singleNumber(vector<int>& nums);
bool test(vector<int>& nums, int answer);
};