We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b56838b commit ff7ed2cCopy full SHA for ff7ed2c
Bit Manipulation/Exclusive OR/a.out
15.4 KB
Bit Manipulation/Exclusive OR/xor.cpp
@@ -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