We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
1 parentf082224 commit69ae9dcCopy full SHA for 69ae9dc
src/main/java/com/fishercoder/solutions/_374.java
@@ -12,31 +12,28 @@ public static class Solution1 {
12
publicintguessNumber(intn) {
13
intleft =1;
14
intright =n;
15
-while (left+1<right) {
+while (left <right) {
16
intmid =left + (right -left) /2;
17
intg =guess(mid);
18
if (g ==0) {
19
returnmid;
20
}elseif (g >0) {
21
-left =mid;
+left =mid +1;
22
}else {
23
-right =mid;
+right =mid -1;
24
}
25
26
-if (guess(left) ==0) {
27
-returnleft;
28
- }
29
-returnright;
+returnguess(left) ==0 ?left :right;
30
31
32
/**
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.
+ * This is a fake guess method that I wrote just tomake the compiler happy,
+ *7 is just a completely random value.
35
*/
36
privateintguess(intnum) {
37
-if (num >6) {
+if (num >7) {
38
return -1;
39
- }elseif (num <6) {
+ }elseif (num <7) {
40
return1;
41
42
return0;