Tags:
"leetcode",
"lru-cache",
access_time 1-min read
LRU Cache Miss Count
Created: March 26, 2019 by [lek-tin]
Last updated: March 26, 2019
Solution
public class CacheMiss {
public int missCount(int[] array, int size) {
if (array == null) return 0;
List<Integer> cache = new LinkedList<>();
int count = 0;
for (int i = 0; i < array.length; i++) {
if (cache.contains(array[i])) {
cache.remove(new Integer(array[i]));
} else {
count++;
if (size == cache.size())
cache.remove(0);
}
cache.add(array[i]);
}
return count;
}
}