320x100
lv.1 2022 KAKAO BLIND RECRUITMENT
https://programmers.co.kr/learn/courses/30/lessons/92334
import java.util.*;
class Solution {
public int[] solution(String[] id_list, String[] report, int k) {
// ๋ฐฐ์ด ์์ฑ (0์ผ๋ก ์๋ ์ด๊ธฐํ)
int[] answer = new int[id_list.length];
// HashMap ์์ฑ (user: ์ ๊ณ ๋นํ ํ์)
HashMap<String, Integer> reports = new HashMap<>(id_list.length);
for (int i = 0;i < id_list.length;i++){
reports.put(id_list[i],0);
}
// ์ ๊ณ ์ค๋ณต ์ ๊ฑฐ(๋ฐฐ์ด->๋ฆฌ์คํธ->ํด์์
)
HashSet<String> report1 = new HashSet<>(Arrays.asList(report));
String[] report2 = report1.toArray(new String[0]);
for(int i = 0; i< report2.length;i++){
String[] users = report2[i].split(" ");
reports.put(users[1], reports.get(users[1]) + 1);
}
for(int i = 0; i< report2.length;i++){
String[] users = report2[i].split(" ");
if (reports.get(users[1]) >= k){
answer[Arrays.asList(id_list).indexOf(users[0])] += 1;
}
}
return answer;
}
}
๋ฐ์ํ
'๐ ์ฝํ ์ฐ์ต์ฅ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] ์ซ์ ๋ฌธ์์ด๊ณผ ์๋จ์ด (0) | 2022.05.09 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] ์์ฃผํ์ง ๋ชปํ ์ ์ (0) | 2022.05.06 |
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ก๋์ ์ต๊ณ ์์์ ์ต์ ์์ (0) | 2022.05.06 |
[CodeUp] python ๊ธฐ์ด 100์ : #6027~ #6064 (0) | 2021.07.18 |
[CodeUp] python ๊ธฐ์ด 100์ : #6001 ~ #6026 (0) | 2021.07.03 |
320x100
lv.1 2022 KAKAO BLIND RECRUITMENT
https://programmers.co.kr/learn/courses/30/lessons/92334
import java.util.*;
class Solution {
public int[] solution(String[] id_list, String[] report, int k) {
// ๋ฐฐ์ด ์์ฑ (0์ผ๋ก ์๋ ์ด๊ธฐํ)
int[] answer = new int[id_list.length];
// HashMap ์์ฑ (user: ์ ๊ณ ๋นํ ํ์)
HashMap<String, Integer> reports = new HashMap<>(id_list.length);
for (int i = 0;i < id_list.length;i++){
reports.put(id_list[i],0);
}
// ์ ๊ณ ์ค๋ณต ์ ๊ฑฐ(๋ฐฐ์ด->๋ฆฌ์คํธ->ํด์์
)
HashSet<String> report1 = new HashSet<>(Arrays.asList(report));
String[] report2 = report1.toArray(new String[0]);
for(int i = 0; i< report2.length;i++){
String[] users = report2[i].split(" ");
reports.put(users[1], reports.get(users[1]) + 1);
}
for(int i = 0; i< report2.length;i++){
String[] users = report2[i].split(" ");
if (reports.get(users[1]) >= k){
answer[Arrays.asList(id_list).indexOf(users[0])] += 1;
}
}
return answer;
}
}
๋ฐ์ํ
'๐ ์ฝํ ์ฐ์ต์ฅ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] ์ซ์ ๋ฌธ์์ด๊ณผ ์๋จ์ด (0) | 2022.05.09 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] ์์ฃผํ์ง ๋ชปํ ์ ์ (0) | 2022.05.06 |
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ก๋์ ์ต๊ณ ์์์ ์ต์ ์์ (0) | 2022.05.06 |
[CodeUp] python ๊ธฐ์ด 100์ : #6027~ #6064 (0) | 2021.07.18 |
[CodeUp] python ๊ธฐ์ด 100์ : #6001 ~ #6026 (0) | 2021.07.03 |