Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created July 16, 2017 07:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jianminchen/386ea4218eeedf0f56c3aaeceb56ec61 to your computer and use it in GitHub Desktop.
Save jianminchen/386ea4218eeedf0f56c3aaeceb56ec61 to your computer and use it in GitHub Desktop.
LRU cache miss - study code written in Java
import java.util.*;
public class Solution {
public static int countMiss(int[] input, int size)
{
List<Integer> list = new LinkedList<>();
int count = 0;
for(int i: input)
{
if(list.contains(i)) list.remove(new Integer(i));
else
{
if(list.size() == size) list.remove(0);
count++;
}
list.add(i);
}
return count;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] input = {1, 1, 3, 4, 5, 6, 1};
System.out.println(countMiss(input, 4));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment