Skip to content

Commit aeb3ae9

Browse files
refactor 278
1 parent 8802fb5 commit aeb3ae9

File tree

1 file changed

+4
-12
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+4
-12
lines changed

src/main/java/com/fishercoder/solutions/_278.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,15 @@ public static class Solution1 {
2626
public int firstBadVersion(int n) {
2727
int left = 1;
2828
int right = n;
29-
if (isBadVersion(left)) {
30-
return left;
31-
}
32-
33-
while (left + 1 < right) {
34-
int mid = left + (right - left) / 2;
29+
while (left < right) {
30+
int mid = left + (right - left)/2;
3531
if (isBadVersion(mid)) {
3632
right = mid;
3733
} else {
38-
left = mid;
34+
left = mid + 1;
3935
}
4036
}
41-
42-
if (isBadVersion(left)) {
43-
return left;
44-
}
45-
return right;
37+
return left;
4638
}
4739

4840
private boolean isBadVersion(int left) {

0 commit comments

Comments
 (0)