Created
April 27, 2016 16:25
-
-
Save mateusmarquezini/55bdb84890c44d50549426fc29e3340f to your computer and use it in GitHub Desktop.
PermCheck - Check whether array A is a permutation (Codility Test)
This file contains 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.Arrays; | |
/** | |
* Created by mateus marquezini on 27-04-2016. | |
*/ | |
public class Solution { | |
public int solution(int[] A) { | |
Arrays.sort(A); | |
if (A[0] != 1) { | |
return 0; | |
} | |
for (int i = 0; i < A.length - 1; i++) { | |
if (A[i] + 1 != A[i + 1]) { | |
return 0; | |
} | |
} | |
return 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment