https://school.programmers.co.kr/learn/courses/30/lessons/178871/
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
import java.util.*;
class Solution {
public String[] solution(String[] players, String[] callings) {
int size = players.length;
Map<String,Integer> findIndex = new HashMap<>();
for(int i = 0 ; i < size ; i++){
findIndex.put(players[i],i);
}
for(String call : callings){
int nowIndex = findIndex.get(call);
int prevIndex = findIndex.get(players[nowIndex-1]);
String temp = players[prevIndex];
players[prevIndex] = players[nowIndex];
players[nowIndex] = temp;
findIndex.put(players[prevIndex],prevIndex);
findIndex.put(players[nowIndex],nowIndex);
}
String[] answer = players;
return answer;
}
}
'알고리즘' 카테고리의 다른 글
프로그래머스 무작위로 K개의 수 뽑기 (JAVA) (0) | 2023.04.22 |
---|---|
프로그래머스 공원 산책 (JAVA) (0) | 2023.04.21 |
프로그래머스 요격 시스템 (JAVA) (0) | 2023.04.19 |
프로그래머스 리코쳇 로봇 (JAVA) (0) | 2023.04.18 |
프로그래머스 점 찍기 (JAVA) (0) | 2023.04.17 |