Skip to content

Commit 374eeb4

Browse files
author
gyeong-hyeon-kim
committed
Solved 1 problem.
1 parent b6f4d2a commit 374eeb4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

level-2/[1차]-캐시.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//완벽한 정답이 아닙니다.
3+
function solution(cacheSize, cities) {
4+
var answer = 0;
5+
let cache = []
6+
if (cacheSize === 0) return 5 * cities.length
7+
for (const city of cities) {
8+
const cityLC = city.toLowerCase()
9+
if (cache.includes(cityLC)) {
10+
cache.splice(cache.indexOf(cityLC), 1)
11+
cache.unshift(cityLC)
12+
answer += 1
13+
} else {
14+
if (cache.length >= cacheSize) cache.pop()
15+
cache.unshift(cityLC)
16+
answer += 5
17+
}
18+
}
19+
return answer;
20+
}

0 commit comments

Comments
 (0)