Skip to content

Commit ff7ed2c

Browse files
committed
added xor in bit manipulation
1 parent b56838b commit ff7ed2c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Bit Manipulation/Exclusive OR/a.out

15.4 KB
Binary file not shown.

Bit Manipulation/Exclusive OR/xor.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
There are n numbers in [1..n]. You're given a set containing n-1 of them. Find the one missing.
3+
4+
Time O(N)
5+
Auxillary Space O(1)
6+
*/
7+
#include<bits/stdc++.h>
8+
using namespace std;
9+
#define ll long long int
10+
#define loop(i,N) for(int i=0;i<N;i++)
11+
#define loop_(i,N) for(int i=1;i<=N;i++)
12+
13+
int main() {
14+
int n;
15+
cin >> n;
16+
int num;
17+
int ans = 0;
18+
for (int i = 1; i <= n; i++) ans ^= i;
19+
for (int i = 1; i <= n - 1; i++) {
20+
cin >> num;
21+
ans ^= num;
22+
}
23+
cout << ans << endl;
24+
return 0;
25+
}

0 commit comments

Comments
 (0)