Skip to content

Commit b97489c

Browse files
authored
Merge pull request #524 from egg-silver/main
[이지은] 64차 라이브코테 제출
2 parents 7462b7b + e537290 commit b97489c

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

live6/test64/문제3/이지은.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
function solution(cacheSize, cities) {
2+
var answer = 0;
3+
cities = cities.map((el) => el.toLowerCase());
4+
5+
let arr = new Map();
6+
7+
for (let i = 0; i < cities.length; i++) {
8+
if (cities.length < 3) {
9+
if (!arr.has(cities[i])) {
10+
arr.set(cities[i]);
11+
answer += 5;
12+
} else {
13+
answer++;
14+
}
15+
} else {
16+
if (arr.has(cities[i])) {
17+
answer++;
18+
} else {
19+
const firstKey = arr.keys().next().value;
20+
arr.delete(firstKey);
21+
arr.set(cities[i]);
22+
23+
answer += 5;
24+
}
25+
}
26+
}
27+
28+
return answer;
29+
}
30+
31+
console.log(
32+
solution(3, [
33+
'Jeju',
34+
'Pangyo',
35+
'Seoul',
36+
'NewYork',
37+
'LA',
38+
'Jeju',
39+
'Pangyo',
40+
'Seoul',
41+
'NewYork',
42+
'LA',
43+
])
44+
);

0 commit comments

Comments
 (0)