Guest User

Untitled

a guest
May 20th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.45 KB | None | 0 0
  1. public class Permutation {
  2.     public static int JOKER = 0;
  3.    
  4.     public static boolean isPermutation(int[] a) {
  5.         int l=a.length;
  6.         for(int i=0; i<l;i++) {
  7.             boolean[] f = new boolean[l+1];
  8.             int n=a[i];
  9.             if(n==JOKER) continue;
  10.             if(n < 1 || n > l) return false;
  11.             if(f[n]) return false;  
  12.             f[n]=true;             
  13.         }
  14.         return true;
  15.     }
  16.    
  17.     public static void main(String[] args) {
  18.         System.out.println(isPermutation(new int[] {1,1,1,4}));
  19.     }
  20.  
  21. }
Add Comment
Please, Sign In to add comment