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

Commit 41669d8

Browse files
Implement solution for minimum operations to zero
1 parent b8b658b commit 41669d8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int makeTheIntegerZero(int num1, int num2) {
3+
int count = 1;
4+
while (true) {
5+
long x = num1 - (long) num2 * count;
6+
if (x < count) {
7+
return -1;
8+
}
9+
if (count >= Long.bitCount(x)) {
10+
return count;
11+
}
12+
count++;
13+
}
14+
}
15+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /