-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirstBadVersion.java
More file actions
36 lines (31 loc) · 818 Bytes
/
firstBadVersion.java
File metadata and controls
36 lines (31 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* Author : WindAsMe
* File : firstBadVersion.java
* Time : Create on 18-9-5
* Location : ../Home/JavaForLeeCode2/firstBadVersion.java
* Function : LeetCode No.278
*/
public class firstBadVersion {
private static int i = 10;
private static boolean isBadVersion(int version) {
return version == i;
}
private static int firstBadVersionResult(int n) {
if (isBadVersion(1))
return 1;
int l = 1;
int r = n;
int mid;
while (l < r) {
mid = l / 2 + r / 2;
if (isBadVersion(mid))
r = mid;
else
l = mid + 1;
}
return l;
}
public static void main(String[] args) {
System.out.println(firstBadVersionResult(15));
}
}