Skip to content

Commit ca68352

Browse files
committed
Solution for Beatiful Arrangement
1 parent 2dc6144 commit ca68352

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Diff for: src/leetcode/BeautifulArrangement.java

+32
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)