-
Notifications
You must be signed in to change notification settings - Fork 0
/
27-03
73 lines (63 loc) · 1.32 KB
/
27-03
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
int missingNumber(int* nums, int numsSize) {
int xorr = 0;
for(int i = 0; i <= numsSize; i++){
xorr ^= i; // counting
}
for(int i = 0; i < numsSize; i++){
xorr ^= nums[i]; // array
}
return xorr;
}
#include <stdio.h>
void KAlgo(int n){
int ans = 0;
while(n > 0){
ans ++;
int rsb = n & (-n);
n -= rsb;
}
printf("Ans from KAlgo = %d", ans);
}
void NormalAlgo(int n){
int ans = 0;
for(int i = 0; i <= 31; i++){
int mask = (1 << i);
if(n & mask){ // result is non zero atleast one bit is on....
ans++;
}
}
printf("Ans from Normal Algo = %d", ans);
}
int main(){
int n = 255;
KAlgo(n);
NormalAlgo(n);
return 0;
}
#include <bits/stdc++.h>
using namespace std;
vector<string> solve(int n){
if(n <= 0){
return {};
}
if(n == 1){
return {"0", "1"};
}
vector<string> ans = solve(n - 1);
vector<string> res;
for(int i = 0; i < ans.size(); i++){
res.push_back("0" + ans[i]);
}
for(int i = ans.size() - 1; i >= 0; i--){
res.push_back("1" + ans[i]);
}
return res;
}
int main(){
int n; cin >> n;
vector<string> ans = solve(n);
for(int i = 0; i < ans.size(); i++){
cout << ans[i] << " ";
}
return 0;
}