Skip to content

Commit b2c2cf0

Browse files
committed
[level 3] Title: N으로 표현, Time: 23.63 ms, Memory: 75.8 MB -BaekjoonHub
1 parent 1a7ce4e commit b2c2cf0

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed
Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,42 @@
11
import java.util.*;
22

33
class Solution {
4-
HashSet<Integer> set = new HashSet<>();
5-
ArrayList<HashSet<Integer>> dp = new ArrayList<>();
64

75
public int solution(int N, int number) {
6+
ArrayList<HashSet<Integer>> dp = new ArrayList<>();
7+
HashSet<Integer> set = new HashSet<>();
88

9-
for(int i = 0; i< 9; i++){
9+
for(int i = 0; i < 9; i ++) {
1010
dp.add(new HashSet<>());
1111
}
1212

13-
for(int i = 1; i< 9; i++){
14-
Set<Integer> currentSet = dp.get(i);
15-
13+
for(int i = 1; i < 9; i++){
14+
HashSet<Integer> currentSet = dp.get(i);
1615
StringBuilder sb = new StringBuilder();
17-
18-
// 이어 붙이기
19-
for(int j = 0; j < i; j++){
16+
for(int j = 0; j < i; j ++){
2017
sb.append(N);
2118
}
19+
2220
currentSet.add(Integer.parseInt(sb.toString()));
2321

2422
// 사칙연산
25-
for(int j = 0; j < i; j++){
26-
Set<Integer> setJ = dp.get(j);
27-
Set<Integer> setK = dp.get(i-j);
23+
for(int j = 1; j < i; j++) {
24+
HashSet<Integer> setJ = dp.get(j);
25+
HashSet<Integer> setK = dp.get(i-j);
2826

2927
for(int num1 : setJ){
3028
for(int num2 : setK){
3129
currentSet.add(num1 + num2);
32-
currentSet.add(num1 - num2);
33-
currentSet.add(num1 * num2);
34-
if(num2 != 0) currentSet.add(num1 / num2);
30+
currentSet.add(num1 - num2);
31+
currentSet.add(num1 * num2);
32+
if(num2 != 0) currentSet.add(num1 / num2);
3533
}
3634
}
3735
}
3836

3937
if(currentSet.contains(number)) return i;
40-
4138
}
39+
4240
return -1;
4341
}
4442
}

프로그래머스/3/42895. N으로 표현/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 성능 요약
66

7-
메모리: 89.5 MB, 시간: 20.42 ms
7+
메모리: 75.8 MB, 시간: 23.63 ms
88

99
### 구분
1010

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2025년 09월 06일 12:11:25
19+
2025년 09월 15일 17:40:23
2020

2121
### 문제 설명
2222

0 commit comments

Comments
 (0)