beat 90% quick java code


  • 0
    J
    private int count = 0;
    public int countArrangement(int N) {
        if(N==0) return 0;
        int[] res = new int[N+1];
        for(int i=0; i<=N; i++) res[i] = i;
        helper(res, N);
        return count;
    
    }
    private void helper(int[] nums, int start) {
        if(start==0){
            count++;
            return;
        }
        for(int i = nums.length-1; i>0; i--){
            if(nums[i]!=0 && (nums[i]%start==0||start%nums[i]==0)) {
                nums[i]=0;
                helper(nums, start-1);
                nums[i] =i;
            }
        }
        
    }
    

    }


Log in to reply
 

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