Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions suyeun84/202509/21 PGM LV3 다단계 칫솔 판매.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
```java
import java.util.*;
class Solution {
static Map<String,Integer> map = new HashMap();
static Map<String,String> recommand = new HashMap();
public int[] solution(String[] enroll, String[] referral, String[] seller, int[] amount) {
int[] count = new int[enroll.length];

for(int i =0; i<enroll.length;i++){
map.put(enroll[i],0);
recommand.put(enroll[i],referral[i]);
}

for(int i=0; i<seller.length; i++){
dfs(seller[i],amount[i]*100);
}

for(int i=0; i<enroll.length;i++){
count[i] = map.get(enroll[i]);
}

return count;

}

public static void dfs(String name, int income){
if(name.equals("-") || income==0){
return;
}

int parents = income/10;
int mine = income-parents;
String next = recommand.get(name);
map.replace(name,map.get(name)+mine);
dfs(next,parents);
}
}
```