forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
63 lines (54 loc) · 1.14 KB
/
Solution.java
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
class Bitset {
private char[] a;
private char[] b;
private int cnt;
public Bitset(int size) {
a = new char[size];
b = new char[size];
Arrays.fill(a, '0');
Arrays.fill(b, '1');
}
public void fix(int idx) {
if (a[idx] == '0') {
a[idx] = '1';
++cnt;
}
b[idx] = '0';
}
public void unfix(int idx) {
if (a[idx] == '1') {
a[idx] = '0';
--cnt;
}
b[idx] = '1';
}
public void flip() {
char[] t = a;
a = b;
b = t;
cnt = a.length - cnt;
}
public boolean all() {
return cnt == a.length;
}
public boolean one() {
return cnt > 0;
}
public int count() {
return cnt;
}
public String toString() {
return String.valueOf(a);
}
}
/**
* Your Bitset object will be instantiated and called as such:
* Bitset obj = new Bitset(size);
* obj.fix(idx);
* obj.unfix(idx);
* obj.flip();
* boolean param_4 = obj.all();
* boolean param_5 = obj.one();
* int param_6 = obj.count();
* String param_7 = obj.toString();
*/