Created
July 16, 2017 07:50
-
-
Save jianminchen/386ea4218eeedf0f56c3aaeceb56ec61 to your computer and use it in GitHub Desktop.
LRU cache miss - study code written in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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