728x90

https://school.programmers.co.kr/learn/courses/30/lessons/176963

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

<관련 내용 : Map 인터페이스 와 해쉬맵>

 

https://xxohii.tistory.com/

 

옥상위로 끌려가고 싶지않은 완두콩

 

xxohii.tistory.com

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];
        
        //name 이름 , yearning : 점수 , photo : 사진
        
        Map <String,Integer> map = new HashMap<>();
        
        //for(int i=0; i< name.length; i++){
        for(int i =0; i< name.length ; i++){
            map.put(name[i],yearning[i]);   
        }
        //{kali=11, don=55, mari=1} 이름에 각자 점수 저장함
        System.out.println(map);
        
        for(int i=0; i<photo.length ; i++){
            String[] groups = photo[i];
            int scores=0;
            
            for(int j=0 ;j<groups.length ;j++){
                String person = groups[j];
                
                    if(map.containsKey(person)){
                        scores += map.get(person); 
                    }
            }
            
            answer[i] = scores;
        }
        
        return answer;
    }
}

 

728x90

'알고리즘공부' 카테고리의 다른 글

프로그래머스 코딩테스트 입문 DAY1  (0) 2025.01.23
A+B 알고리즘  (0) 2024.05.30
[프로그래머스] 문자열 내 p와 y의 개수  (0) 2024.05.24
[3단계]8393번 합  (0) 2022.01.14
[3단계]10950 A+B-3  (0) 2022.01.14

+ Recent posts