Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcd7a6ad

Browse files
add 2166
1 parent4681e47 commitcd7a6ad

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|2166|[Design Bitset](https://leetcode.com/problems/design-bitset/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2166.java)||Medium||
1112
|2165|[Smallest Value of the Rearranged Number](https://leetcode.com/problems/smallest-value-of-the-rearranged-number/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2165.java)||Medium||
1213
|2164|[Sort Even and Odd Indices Independently](https://leetcode.com/problems/sort-even-and-odd-indices-independently/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2164.java)||Easy||
1314
|2161|[Partition Array According to Given Pivot](https://leetcode.com/problems/partition-array-according-to-given-pivot/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2161.java)||Medium||
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_2166 {
4+
publicstaticclassSolution1 {
5+
classBitset {
6+
7+
intsize;
8+
intones;
9+
int[]nums1;
10+
int[]nums2;
11+
booleancheckingNums1;
12+
13+
publicBitset(intsize) {
14+
this.nums1 =newint[size];
15+
this.nums2 =newint[size];
16+
for (inti =0;i <size;i++) {
17+
nums2[i] =1;
18+
}
19+
this.ones =0;
20+
this.size =size;
21+
this.checkingNums1 =true;
22+
}
23+
24+
publicvoidfix(intidx) {
25+
if (this.checkingNums1) {
26+
if (nums1[idx] ==0) {
27+
ones++;
28+
}
29+
nums1[idx] =1;
30+
nums2[idx] =0;
31+
}else {
32+
if (nums2[idx] ==0) {
33+
ones++;
34+
}
35+
nums2[idx] =1;
36+
nums1[idx] =0;
37+
}
38+
}
39+
40+
publicvoidunfix(intidx) {
41+
if (this.checkingNums1) {
42+
if (nums1[idx] ==1) {
43+
ones--;
44+
}
45+
nums1[idx] =0;
46+
nums2[idx] =1;
47+
}else {
48+
if (nums2[idx] ==1) {
49+
ones--;
50+
}
51+
nums2[idx] =0;
52+
nums1[idx] =1;
53+
}
54+
}
55+
56+
publicvoidflip() {
57+
this.ones =this.size -this.ones;
58+
this.checkingNums1 = !this.checkingNums1;
59+
}
60+
61+
publicbooleanall() {
62+
returnones ==size;
63+
}
64+
65+
publicbooleanone() {
66+
returnones >0;
67+
}
68+
69+
publicintcount() {
70+
returnones;
71+
}
72+
73+
publicStringtoString() {
74+
StringBuildersb =newStringBuilder();
75+
if (this.checkingNums1) {
76+
for (inti =0;i <size;i++) {
77+
sb.append(nums1[i]);
78+
}
79+
}else {
80+
for (inti =0;i <size;i++) {
81+
sb.append(nums2[i]);
82+
}
83+
}
84+
returnsb.toString();
85+
}
86+
}
87+
}
88+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp