This file contains hidden or 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
def maxArea(self, heights: List[int]) -> int: | |
max_area = 0 | |
n = len(heights) | |
for i in range(n): | |
for j in reversed(range(i+1, n)): | |
width = j - i | |
height = min(heights[i], heights[j]) | |
max_area = max(max_area, width * height) | |
return max_area |
This file contains hidden or 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
def maxArea(heights: List[int]) -> int: | |
max_area = 0 | |
n = len(heights) | |
for i in range(n): | |
for j in range(i+1, n): | |
width = j - i | |
height = min(heights[i], heights[j]) | |
max_area = max(max_area, width * height) | |
return max_area |
This file contains hidden or 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
def maxProfit(prices: List[int]) -> int: | |
max_profit = 0 | |
buy_time = 0 | |
for sell_time in range(1, len(prices)): | |
if prices[sell_time] < prices[buy_time]: | |
buy_time = sell_time | |
else: | |
max_profit = max(max_profit, prices[sell_time] - prices[buy_time]) | |
return max_profit |
This file contains hidden or 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
def maxProfit(prices: List[int]) -> int: | |
end_time = len(prices) | |
max_profit = 0 | |
for buy_time in range(end_time): | |
for sell_time in range(buy_time+1, end_time): | |
profit = prices[sell_time] - prices[buy_time] | |
if profit > max_profit: | |
max_profit = profit | |
return max_profit |
This file contains hidden or 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
package com.murex.booking.sequence.sweeper.utils; | |
import java.util.LinkedHashMap; | |
import java.util.Map; | |
import java.util.function.Consumer; | |
public class LRUResourceCache<K, V> extends LinkedHashMap<K, V> { | |
private final int capacity; | |
private final Consumer<V> closeResource; |
This file contains hidden or 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
public class LRUCache<K, V> extends LinkedHashMap<K, V> { | |
private final int capacity; | |
public LRUCache(int capacity) { | |
this.capacity = capacity; | |
} | |
@Override | |
protected boolean removeEldestEntry(Map.Entry<K, V> oldest) { | |
return size() > capacity; |
This file contains hidden or 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
@functools.lru_cache(maxsize=2) | |
def long_computation(arg): | |
print("Long computation", arg) | |
return ... | |
for arg in [1,2,3] * 2: | |
long_computation(arg) | |
# Will print (only cache misses!) | |
"Long computation 1" |
This file contains hidden or 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
@functools.lru_cache(maxsize=YOUR_CACHE_SIZE) | |
def long_computation(arg1, arg2, arg3): | |
pass |
This file contains hidden or 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
class LRUCache: | |
def __init__(self, max_size): | |
self.dict = OrderedDict() | |
self.max_size = max_size | |
def __len__(self): | |
return len(self.dict) | |
def __contains__(self, key): | |
if key in self.dict: |
This file contains hidden or 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
public class LRUCache<K, V> extends LinkedHashMap<K, V> { | |
private final int capacity; | |
public LRUCache(int capacity) { | |
super(capacity, 0.75f, true); | |
this.capacity = capacity; | |
} | |
@Override | |
protected boolean removeEldestEntry(Map.Entry<K, V> oldest) { |