//구글콘솔 광고 추가가
달리기 경주 문제

 

내 코드
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
    public string[] solution(string[] players, string[] callings) {
        List<string> answer = new List<string>();
        Dictionary<string, int> resultDic = new Dictionary<string, int>();
        List<string> list = new List<string>();
        int num = 0;
        foreach(string player in players)
        {
            resultDic.Add(player, num);
            num++;
        }
        foreach(string call in callings)
        {
            int n = resultDic[call];
            string name = players[n - 1];
            players[resultDic[call]-1] = call;
            
            //추월당한 사람 이름
            //var _key = resultDic.FirstOrDefault(x => x.Value == resultDic[call] - 1).Key;
            
            players[resultDic[call]] = name;
            
            resultDic[name]++; //추월 당한 사람 순위 ++
            resultDic[call]--; //추월 하려는 사람 순위 --

        }
        return players;
    }
}
728x90

+ Recent posts