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

Commitd7d90e6

Browse files
add 2220
1 parentc86b148 commitd7d90e6

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-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+
| 2220|[Minimum Bit Flips to Convert Number](https://leetcode.com/problems/minimum-bit-flips-to-convert-number/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2220.java)|| Easy||
1112
| 2215|[Find the Difference of Two Arrays](https://leetcode.com/problems/find-the-difference-of-two-arrays/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2215.java)|| Easy||
1213
| 2210|[Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2210.java)|| Easy||
1314
| 2208|[Minimum Operations to Halve Array Sum](https://leetcode.com/problems/minimum-operations-to-halve-array-sum/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2208.java)|| Medium||
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_2220 {
4+
publicstaticclassSolution1 {
5+
publicintminBitFlips(intstart,intgoal) {
6+
StringsBin =Integer.toBinaryString(start);
7+
Strings =String.format("%32s",sBin).replaceAll(" ","0");
8+
StringgBin =Integer.toBinaryString(goal);
9+
Stringg =String.format("%32s",gBin).replaceAll(" ","0");
10+
intans =0;
11+
for (inti =0;i <s.length();i++) {
12+
if (s.charAt(i) !=g.charAt(i)) {
13+
ans++;
14+
}
15+
}
16+
returnans;
17+
}
18+
}
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._2220;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_2220Test {
10+
privatestatic_2220.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_2220.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(3,solution1.minBitFlips(10,7));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp