Skip to content

Instantly share code, notes, and snippets.

@stephen-maina
Created April 13, 2015 12:35
Show Gist options
  • Save stephen-maina/6c7c8a5cb6c72d0ffaf4 to your computer and use it in GitHub Desktop.
Save stephen-maina/6c7c8a5cb6c72d0ffaf4 to your computer and use it in GitHub Desktop.
MissingInteger Codility Lesson 2
import java.util.stream.IntStream;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
if(A.length==1){
return A[0]+1;
}
int[] sorted=IntStream.of(A).sorted().toArray();
int temp=sorted[0];
for(int index=1;index<sorted.length;index++){
if(temp<sorted[index]&&temp+1==sorted[index]){
temp=sorted[index];
}else if(temp==sorted[index]){
continue;
}else{
return sorted[index-1]+1;
}
}
return A[A.length-1]+1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment