Guozi149
BAN USERLinkedHashMap. Cannot post link, so you can google it.
impletement LRU class which extends LinkedHashMap and override removeEldestEntry like this:
class LRULinkedHashMap<K,V> extends LinkedHashMap<K,V>{
private int capacity;
LRULinkedHashMap(int capacity){
super(16,0.75f,true);
this.capacity=capacity;
}
@Override
protected boolean removeEldestEntry(Map.Entry<K, V> eldest){
return size() > capacity;
}
}
When n equals 3, result2 should be {9,1}?
If so, here is my pseudo-code:
while array1.length >n:
newArray = new Array();
for(int i = 0; i < array1.length/n +1; i++)
{
newArray.Add(sum(array, i*n, i*(n+1)-1); // Calculate the sum of from array1[i*n] to array1[i*(n+1)-1], and please attention to the range of index when calculating the last several numbers
}
array1 = newArray
if not, would you please to provide me more info? Thanks.
- Guozi149 October 07, 2015
I think we should use Divide and Conquer for efficiency when we impletement recursive version.
- Guozi149 October 12, 2015