File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ 2166. Design Bitset
3+
4+ Submitted: February 28, 2025
5+
6+ Runtime: 1206 ms (beats 21.92%)
7+ Memory: 49.69 MB (beats 96.58%)
8+ """
9+
10+ class Bitset :
11+
12+ def __init__ (self , size : int ):
13+ self .size = size
14+ self .data = 0
15+
16+ def fix (self , idx : int ) -> None :
17+ self .data |= (1 << idx )
18+
19+ def unfix (self , idx : int ) -> None :
20+ self .data &= ~ (1 << idx )
21+
22+ def flip (self ) -> None :
23+ self .data = (~ self .data & (1 << self .size ) - 1 )
24+
25+ def all (self ) -> bool :
26+ return self .data == (1 << self .size ) - 1
27+
28+ def one (self ) -> bool :
29+ return bool (self .data )
30+
31+ def count (self ) -> int :
32+ return self .data .bit_count ()
33+
34+ def toString (self ) -> str :
35+ return bin (self .data )[2 :].zfill (self .size )[::- 1 ]
36+
37+ # Your Bitset object will be instantiated and called as such:
38+ # obj = Bitset(size)
39+ # obj.fix(idx)
40+ # obj.unfix(idx)
41+ # obj.flip()
42+ # param_4 = obj.all()
43+ # param_5 = obj.one()
44+ # param_6 = obj.count()
45+ # param_7 = obj.toString()
You can’t perform that action at this time.
0 commit comments