@@ -30,7 +30,7 @@ public class SmallestMissingNumber {
30
30
* @return
31
31
*/
32
32
public static int smallestMissingNumber (int [] a , int low , int high ) {
33
- if (low < high ) {
33
+ if (low <= high ) {
34
34
int mid = (low + high ) / 2 ;
35
35
36
36
if (a [mid ] == mid ) {
@@ -46,9 +46,11 @@ public static int smallestMissingNumber(int[] a, int low, int high) {
46
46
}
47
47
48
48
public static void main (String a []) {
49
+ System .out .println (smallestMissingNumber (new int []{0 , 1 }, 0 , 1 ));
49
50
System .out .println (smallestMissingNumber (new int []{0 , 1 , 2 , 6 , 9 }, 0 , 4 ));
50
51
System .out .println (smallestMissingNumber (new int []{4 , 5 , 10 , 11 }, 0 , 3 ));
52
+ System .out .println (smallestMissingNumber (new int []{0 , 4 , 5 , 10 , 56 }, 0 , 4 ));
51
53
System .out .println (smallestMissingNumber (new int []{0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 10 }, 0 , 8 ));
52
- System .out .println (smallestMissingNumber (new int []{0 , 1 , 3 , 3 , 11 }, 0 , 4 )); // doesn't work
54
+ System .out .println (smallestMissingNumber (new int []{0 , 1 , 2 , 3 , 3 }, 0 , 4 )); // doesn't work
53
55
}
54
56
}
0 commit comments