Created
April 13, 2015 05:59
-
-
Save stephen-maina/269b9d9514abe4cddacb to your computer and use it in GitHub Desktop.
PermMissingElem Codility lesson 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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