Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Permutation {
- public static int JOKER = 0;
- public static boolean isPermutation(int[] a) {
- int l=a.length;
- for(int i=0; i<l;i++) {
- boolean[] f = new boolean[l+1];
- int n=a[i];
- if(n==JOKER) continue;
- if(n < 1 || n > l) return false;
- if(f[n]) return false;
- f[n]=true;
- }
- return true;
- }
- public static void main(String[] args) {
- System.out.println(isPermutation(new int[] {1,1,1,4}));
- }
- }
Add Comment
Please, Sign In to add comment