We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2dc6144 commit ca68352Copy full SHA for ca68352
src/leetcode/BeautifulArrangement.java
@@ -0,0 +1,32 @@
1
+package leetcode;
2
+
3
+public class BeautifulArrangement {
4
5
+ int sum=0;
6
+ public static void main(String[] args) {
7
+ BeautifulArrangement test = new BeautifulArrangement();
8
+ System.out.println(test.countArrangement(2));
9
10
+ }
11
12
+ public int countArrangement(int N) {
13
+ boolean[] v = new boolean[N+1];
14
+ arrangement(N,1, v);
15
+ return sum;
16
17
18
+ public void arrangement(int n, int pos, boolean[] v){
19
+ if(pos > n){
20
+ sum++;
21
+ // return;
22
23
+ for(int i=1; i<=n; i++){
24
+ if(!v[i] && (i%pos==0 || pos%i==0)){
25
+ v[i]=true;
26
+ arrangement(n,pos+1, v);
27
+ v[i]=false;
28
29
30
31
32
+}
0 commit comments