Skip to content

Instantly share code, notes, and snippets.

@zzlalani
Created January 31, 2019 18:11
Show Gist options
  • Save zzlalani/5a2bffe567b2d1e5ad3fe155d1b5705a to your computer and use it in GitHub Desktop.
Save zzlalani/5a2bffe567b2d1e5ad3fe155d1b5705a to your computer and use it in GitHub Desktop.
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Arrays;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
Arrays.sort(A);
if (A[A.length - 1] < 1) {
return 1;
}
for (int i = 0; i < A.length; i ++) {
if (i == 0) {
continue;
}
if (A[i] == A[i - 1]) {
continue;
}
if (A[i] == A[i - 1] + 1) {
continue;
} else {
return A[i - 1] + 1;
}
}
return A[A.length - 1] + 1;
}
public static void main(String [] args) {
Solution sol = new Solution();
System.out.println(sol.solution(new int[] {2}));
System.out.println(sol.solution(new int[] {1, 3, 6, 4, 1, 2}));
System.out.println(sol.solution(new int[] {1,2,3}));
System.out.println(sol.solution(new int[] {-1, -3}));
int[] arr = new int[100000];
for (int a = 0; a < 100000; a++) {
arr[a] = 100 + a;
}
arr[1000] = 1000000;
System.out.println(arr[arr.length - 1]);
System.out.println(sol.solution(arr));
// for ( int a = 0; a < 100000; a++ ) {
// System.out.println(a);
// }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment