Skip to content

Commit 24e2a80

Browse files
authored
Create 28 PGM N으로 표현.md
1 parent 07ba6c8 commit 24e2a80

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
```java
2+
import java.util.*;
3+
4+
class Solution {
5+
public int solution(int N, int number) {
6+
if (N == number) {
7+
return 1;
8+
}
9+
10+
List<Set<Integer>> num = new ArrayList<>();
11+
for (int i = 0; i <= 8; i++) {
12+
num.add(new HashSet<>());
13+
}
14+
15+
num.get(1).add(N);
16+
17+
for (int i = 2; i <= 8; i++) {
18+
StringBuilder sb = new StringBuilder().append(N);
19+
for (int j = 1; j < i; j++) {
20+
sb.append(N);
21+
}
22+
num.get(i).add(Integer.parseInt(sb.toString()));
23+
24+
for (int j = 1; j < i; j++) {
25+
int k = i - j;
26+
for (int num1 : num.get(j)) {
27+
for (int num2 : num.get(k)) {
28+
num.get(i).add(num1 + num2);
29+
num.get(i).add(num1 - num2);
30+
num.get(i).add(num1 * num2);
31+
if (num2 != 0) {
32+
num.get(i).add(num1 / num2);
33+
}
34+
}
35+
}
36+
}
37+
38+
if (num.get(i).contains(number)) {
39+
return i;
40+
}
41+
}
42+
43+
return -1;
44+
}
45+
}
46+
```

0 commit comments

Comments
 (0)