全部评论
也是跪在输入输出了,哎!
package bianlifeng;
import java.util.LinkedHashMap;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
LRUCache lruCache4 = new LRUCache(n);
String str;
while ((str = sc.nextLine()).contains(" ")){
String[] split = str.split(" ");
int key = Integer.parseInt(split[0]);
int value = Integer.parseInt(split[1]);
lruCache4.put(key, value);
}
int key = Integer.parseInt(str);
System.out.println(lruCache4.get(key));
}
}
class LRUCache {
public int capacity;
public LinkedHashMap<Integer, Integer> map;
public LRUCache(int capacity) {
this.capacity = capacity;
map = new LinkedHashMap<>();
}
public int get(int key) {
if (map.containsKey(key)) {
int value = map.get(key);
map.remove(key);
map.put(key, value);
return value;
} else {
return -1;
}
}
public void put(int key, int value) {
if (map.containsKey(key)) {
map.remove(key);
}
if (map.size() >= capacity) {
map.remove(map.keySet().iterator().next());
}
map.put(key, value);
}
}
我第三题的python也是跪在输入输出上了, 有没有大佬通过的呀
相关推荐
![](https://static.nowcoder.com/fe/file/oss/1716965564844UEBJN.png)
![](https://static.nowcoder.com/fe/file/oss/1716965585666UBBME.png)
腾讯
| 实习
| 超多精选岗位
点赞 评论 收藏
分享
![](https://static.nowcoder.com/fe/file/oss/1716965564844UEBJN.png)
![](https://static.nowcoder.com/fe/file/oss/1716965585666UBBME.png)
顺丰集团
| 校招
| 超多精选岗位
点赞 评论 收藏
分享
01-17 10:48
南昌理工学院 Java 点赞 评论 收藏
分享