티스토리 뷰
[문제]
[해설]
- 진짜 오랜만에 코테를 푼다. 감각도 살릴겸 쉬운 문제를 풀었다.
- 일부러 solution method 외에 findScore method를 만들어 로직을 분리했다.(이런 연습도 해봐야 할 것 같아서 그랬다.)
- 문제를 읽은 후 어떻게 풀어야 할까 고민하다보니 Map을 이용하면 적절할 것 같았다.
import java.util.Map;
import java.util.HashMap;
class Solution {
public int[] solution(String[] name, int[] yearning, String[][] photo) {
int[] answer = new int[photo.length];
Map<String, Integer> nsMap = new HashMap<String, Integer>();
for(int i = 0; i < name.length; i++) nsMap.put(name[i], yearning[i]);
for(int k = 0; k < photo.length; k++) {
answer[k] = this.findScore(nsMap, photo[k]);
}
return answer;
}
private int findScore(Map<String, Integer> nsMap, String[] tmpNames) {
int sum = 0;
for(int j = 0; j < tmpNames.length; j++) {
if(nsMap.containsKey(tmpNames[j])) sum += nsMap.get(tmpNames[j]);
}
return sum;
}
}
'흥미 > 코딩테스트' 카테고리의 다른 글
#25😊 완주하지 못한 선수 (0) | 2023.07.15 |
---|---|
#24😂 달리기 경주 / indexOf는 시간복잡도가 많이 든다! (0) | 2023.04.16 |
#22 😂 체육복 with Greedy algorithm (0) | 2023.03.28 |
#21 😊 프로그래머스 - 콜라 문제(Level 1) with 재귀함수 (0) | 2023.03.16 |
#20 😂 프로그래머스 - 카드 뭉치(Level 1) / Queue 사용해보기 (1) | 2023.03.15 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Java8
- db
- Spring Boot
- API
- spring
- Phaser
- nosql
- Advanced Stream
- 빅데이터
- 프로그래머스
- 프로세스
- Stream
- 운영체제
- SpringBoot
- 빅데이터 분석기사
- SQL
- jpa
- 코딩테스트
- 메모리
- Phaser3
- OS
- node.js
- MongoDB
- git
- MySQL
- 코테
- 알고리즘
- java
- 자료구조
- DART
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
글 보관함