We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b6f4d2a commit 374eeb4Copy full SHA for 374eeb4
level-2/[1차]-캐시.js
@@ -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
16
+ answer += 5
17
+ }
18
19
+ return answer;
20
+}
0 commit comments