Skip to content

Instantly share code, notes, and snippets.

@stephen-maina
Created April 13, 2015 05:59
Show Gist options
  • Save stephen-maina/269b9d9514abe4cddacb to your computer and use it in GitHub Desktop.
Save stephen-maina/269b9d9514abe4cddacb to your computer and use it in GitHub Desktop.
PermMissingElem 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==0){
return 1;
}
int []sorted = IntStream.of(A).sorted().toArray();
if(sorted[sorted.length-1]!=sorted.length+1){
return sorted.length+1;
}
for(int index=0;index<sorted.length;index++){
int check=index+1;
if(sorted[index]!=check){
return check;
}
}
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment