File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed
main/java/g0201_0300/s0278_first_bad_version
test/java/g0201_0300/s0278_first_bad_version Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 77boolean isBadVersion(int version); */
88
99public class Solution extends VersionControl {
10+ public Solution (int bad ) {
11+ super (bad );
12+ }
13+
1014 public int firstBadVersion (int n ) {
1115 int start = 1 ;
1216 int end = n ;
Original file line number Diff line number Diff line change 77boolean isBadVersion(int version); */
88
99public class VersionControl {
10+ private int bad ;
11+
12+ public VersionControl (int bad ) {
13+ this .bad = bad ;
14+ }
15+
1016 public boolean isBadVersion (int version ) {
11- return version % 2 == 0 ;
17+ return version >= bad ;
1218 }
1319}
Original file line number Diff line number Diff line change 88class SolutionTest {
99 @ Test
1010 void firstBadVersion () {
11- assertThat (new Solution ().firstBadVersion (5 ), equalTo (4 ));
11+ assertThat (new Solution (4 ).firstBadVersion (5 ), equalTo (4 ));
1212 }
1313
1414 @ Test
1515 void firstBadVersion2 () {
16- assertThat (new Solution ().firstBadVersion (1 ), equalTo (1 ));
16+ assertThat (new Solution (1 ).firstBadVersion (1 ), equalTo (1 ));
17+ }
18+
19+ @ Test
20+ void firstBadVersion3 () {
21+ assertThat (new Solution (98 ).firstBadVersion (99 ), equalTo (98 ));
22+ }
23+
24+ void firstBadVersion4 () {
25+ assertThat (new Solution (32 ).firstBadVersion (99 ), equalTo (98 ));
1726 }
1827}
You can’t perform that action at this time.
0 commit comments