forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.go
60 lines (51 loc) · 1.01 KB
/
Solution.go
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
type Bitset struct {
a []byte
b []byte
cnt int
}
func Constructor(size int) Bitset {
a := bytes.Repeat([]byte{'0'}, size)
b := bytes.Repeat([]byte{'1'}, size)
return Bitset{a, b, 0}
}
func (this *Bitset) Fix(idx int) {
if this.a[idx] == '0' {
this.a[idx] = '1'
this.cnt++
}
this.b[idx] = '0'
}
func (this *Bitset) Unfix(idx int) {
if this.a[idx] == '1' {
this.a[idx] = '0'
this.cnt--
}
this.b[idx] = '1'
}
func (this *Bitset) Flip() {
this.a, this.b = this.b, this.a
this.cnt = len(this.a) - this.cnt
}
func (this *Bitset) All() bool {
return this.cnt == len(this.a)
}
func (this *Bitset) One() bool {
return this.cnt > 0
}
func (this *Bitset) Count() int {
return this.cnt
}
func (this *Bitset) ToString() string {
return string(this.a)
}
/**
* Your Bitset object will be instantiated and called as such:
* obj := Constructor(size);
* obj.Fix(idx);
* obj.Unfix(idx);
* obj.Flip();
* param_4 := obj.All();
* param_5 := obj.One();
* param_6 := obj.Count();
* param_7 := obj.ToString();
*/