forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.cpp
53 lines (44 loc) · 917 Bytes
/
Solution.cpp
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
class Bitset {
public:
string a, b;
int cnt = 0;
Bitset(int size) {
a = string(size, '0');
b = string(size, '1');
}
void fix(int idx) {
if (a[idx] == '0') a[idx] = '1', ++cnt;
b[idx] = '0';
}
void unfix(int idx) {
if (a[idx] == '1') a[idx] = '0', --cnt;
b[idx] = '1';
}
void flip() {
swap(a, b);
cnt = a.size() - cnt;
}
bool all() {
return cnt == a.size();
}
bool one() {
return cnt > 0;
}
int count() {
return cnt;
}
string toString() {
return a;
}
};
/**
* Your Bitset object will be instantiated and called as such:
* Bitset* obj = new Bitset(size);
* obj->fix(idx);
* obj->unfix(idx);
* obj->flip();
* bool param_4 = obj->all();
* bool param_5 = obj->one();
* int param_6 = obj->count();
* string param_7 = obj->toString();
*/