Simple Java Solution


  • 0
    G
    public class Solution {
        public int countArrangement(int N) {
            return ca(N, new int[N+1]);
        }
        public int ca(int N, int[] res){
            if(N==0)    return 1;
            int r = 0;
            for(int i = 1; i< res.length; i++){
                if(res[i] == 0){
                    if(N%i==0 || i%N==0){
                        res[i] = N;
                        r+= ca(N-1, res);
                        res[i] = 0;
                    }
                }
            }
            return r;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.