mirror of
https://github.com/20kaushik02/leetcode-gulag.git
synced 2025-12-06 10:44:06 +00:00
day 8: 136-single-number
This commit is contained in:
parent
32366c1e21
commit
df64aaced5
9
136-single-number/driver.cpp
Normal file
9
136-single-number/driver.cpp
Normal 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;
|
||||||
|
}
|
||||||
15
136-single-number/soln.cpp
Normal file
15
136-single-number/soln.cpp
Normal 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;
|
||||||
|
}
|
||||||
9
136-single-number/soln.hpp
Normal file
9
136-single-number/soln.hpp
Normal 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);
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user