Skip to content

Commit b4a31e3

Browse files
committed
64차 3번 문제풀이
1 parent a636a16 commit b4a31e3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

live6/test64/문제3/임동민.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function solution(cacheSize, cities) {
2+
const stack = [];
3+
let time = 0;
4+
5+
if(cacheSize === 0){
6+
return cities.length * 5;
7+
}
8+
9+
cities.forEach(e => {
10+
const lower = e.toLowerCase();
11+
if(stack.includes(lower)){
12+
time += 1;
13+
stack.splice(stack.indexOf(lower),1);
14+
stack.push(lower);
15+
} else {
16+
time += 5;
17+
18+
if(stack.length >= cacheSize){
19+
stack.shift();
20+
}
21+
22+
stack.push(lower);
23+
}
24+
25+
})
26+
return time;
27+
}

0 commit comments

Comments
 (0)