Skip to content

Commit 58e517e

Browse files
authored
[20250921] PGM / LV3 / 다단계 칫솔 판매 / 김수연
1 parent 40eabd2 commit 58e517e

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
```java
2+
import java.util.*;
3+
class Solution {
4+
static Map<String,Integer> map = new HashMap();
5+
static Map<String,String> recommand = new HashMap();
6+
public int[] solution(String[] enroll, String[] referral, String[] seller, int[] amount) {
7+
int[] count = new int[enroll.length];
8+
9+
for(int i =0; i<enroll.length;i++){
10+
map.put(enroll[i],0);
11+
recommand.put(enroll[i],referral[i]);
12+
}
13+
14+
for(int i=0; i<seller.length; i++){
15+
dfs(seller[i],amount[i]*100);
16+
}
17+
18+
for(int i=0; i<enroll.length;i++){
19+
count[i] = map.get(enroll[i]);
20+
}
21+
22+
return count;
23+
24+
}
25+
26+
public static void dfs(String name, int income){
27+
if(name.equals("-") || income==0){
28+
return;
29+
}
30+
31+
int parents = income/10;
32+
int mine = income-parents;
33+
String next = recommand.get(name);
34+
map.replace(name,map.get(name)+mine);
35+
dfs(next,parents);
36+
}
37+
}
38+
```

0 commit comments

Comments
 (0)