Skip to content

Instantly share code, notes, and snippets.

@mateusmarquezini
Created April 27, 2016 16:25
Show Gist options
  • Save mateusmarquezini/55bdb84890c44d50549426fc29e3340f to your computer and use it in GitHub Desktop.
Save mateusmarquezini/55bdb84890c44d50549426fc29e3340f to your computer and use it in GitHub Desktop.
PermCheck - Check whether array A is a permutation (Codility Test)
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