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

Commit69ae9dc

Browse files
refactor 374
1 parentf082224 commit69ae9dc

File tree

1 file changed

+8
-11
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+8
-11
lines changed

‎src/main/java/com/fishercoder/solutions/_374.java‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,28 @@ public static class Solution1 {
1212
publicintguessNumber(intn) {
1313
intleft =1;
1414
intright =n;
15-
while (left+1<right) {
15+
while (left <right) {
1616
intmid =left + (right -left) /2;
1717
intg =guess(mid);
1818
if (g ==0) {
1919
returnmid;
2020
}elseif (g >0) {
21-
left =mid;
21+
left =mid +1;
2222
}else {
23-
right =mid;
23+
right =mid -1;
2424
}
2525
}
26-
if (guess(left) ==0) {
27-
returnleft;
28-
}
29-
returnright;
26+
returnguess(left) ==0 ?left :right;
3027
}
3128

3229
/**
33-
* This is a fake guess method that I wrote just tocompile/test, I'll have to change it to
34-
*another number other than 6 based on the number to be found.
30+
* This is a fake guess method that I wrote just tomake the compiler happy,
31+
*7 is just a completely random value.
3532
*/
3633
privateintguess(intnum) {
37-
if (num >6) {
34+
if (num >7) {
3835
return -1;
39-
}elseif (num <6) {
36+
}elseif (num <7) {
4037
return1;
4138
}else {
4239
return0;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp