Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d7d90e6

Browse files
add 2220
1 parent c86b148 commit d7d90e6

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+
package com.fishercoder.solutions;
2+
3+
public class _2220 {
4+
public static class Solution1 {
5+
public int minBitFlips(int start, int goal) {
6+
String sBin = Integer.toBinaryString(start);
7+
String s = String.format("%32s", sBin).replaceAll(" ", "0");
8+
String gBin = Integer.toBinaryString(goal);
9+
String g = String.format("%32s", gBin).replaceAll(" ", "0");
10+
int ans = 0;
11+
for (int i = 0; i < s.length(); i++) {
12+
if (s.charAt(i) != g.charAt(i)) {
13+
ans++;
14+
}
15+
}
16+
return ans;
17+
}
18+
}
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._2220;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _2220Test {
10+
private static _2220.Solution1 solution1;
11+
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _2220.Solution1();
15+
}
16+
17+
@Test
18+
public void test1() {
19+
assertEquals(3, solution1.minBitFlips(10, 7));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)