import java.util.ArrayList;
import java.util.List;
// IMPORT LIBRARY PACKAGES NEEDED BY YOUR PROGRAM// SOME CLASSES WITHIN A PACKAGE MAY BE RESTRICTED// DEFINE ANY CLASS AND METHOD NEEDED// CLASS BEGINS, THIS CLASS IS REQUIREDpublicclassFirstInOutPage
{// METHOD SIGNATURE BEGINS, THIS METHOD IS REQUIREDpublicstaticintcountCacheMiss(int max_cache_size, int[] page_requests)
{
// INSERT YOUR CODE HERE
List<Integer> list = new ArrayList<Integer>();
int count=0;
for(int i=0;i<page_requests.length;i++){
if (list.indexOf(page_requests[i])>-1) {
count++;
}else {
if (list.size()==max_cache_size) {
list.remove(0);
list.add(page_requests[i]);
}else {
list.add(page_requests[i]);
}
}
}
count=page_requests.length-count;
return count;
}
// METHOD SIGNATURE ENDS
}
2016年4月21日百度笔试题–FirstInOutPageimport java.util.ArrayList;import java.util.List;// IMPORT LIBRARY PACKAGES NEEDED BY YOUR PROGRAM// SOME CLASSES WITHIN A PACKAGE MAY BE RESTRICTED// DEFINE ANY CLASS