Skip to content

Commit 77cb0a2

Browse files
authored
solve 달리기경주 with cpp
1 parent f624201 commit 77cb0a2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

달리기경주/solution.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <unordered_map>
4+
5+
using namespace std;
6+
7+
vector<string> solution(vector<string> players, vector<string> callings) {
8+
unordered_map<string, int> indexMap;
9+
10+
for (int i = 0; i < players.size(); ++i) {
11+
indexMap[players[i]] = i;
12+
}
13+
14+
for (const auto& calling : callings) {
15+
int index = indexMap[calling];
16+
swap(players[index], players[index - 1]);
17+
indexMap[calling] = index - 1;
18+
indexMap[players[index]] = index;
19+
}
20+
21+
return players;
22+
}

0 commit comments

Comments
 (0)