雕刻时光

just do it……nothing impossible
随笔 - 547, 文章 - 0, 评论 - 82, 阅读 - 86万
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

2023年5月27日

https://www.nowcoder.com/practice/5dfded165916435d9defb053c63f1e84?tpId=295&tqId=2427094&ru=/exam/oj&qru=/ta/format-top101/question-ranking&sourceUrl=%2Fexam%2Foj

public class Solution {
    Map<Integer,Integer> map;
    int capacity;
    public Solution(int capacity) {
         // write code here
        this.capacity = capacity;
        // LinkedHashMap可以保证插入有序
        map = new LinkedHashMap<>(capacity);
    }
 
    public int get(int key) {
         // write code here
        Integer value = map.get(key);
        if(value!=null){
            if(map.size()>1){
                map.remove(key);
                map.put(key,value); // 存入最后
            }
        }else{
            return -1;
        }
        return value;
    }
 
    public void set(int key, int value) {
         // write code here
        if(map.containsKey(key)){
            map.remove(key);
        }
        if(map.size()>=capacity){
            //这中相当于有一个指针,指向第一个数的前面 keySet() 返回key的集合
            //next() 取出下一个数,指针指向下一位
            Integer firstKey = map.keySet().iterator().next();
            map.remove(firstKey);
        }
        map.put(key,value);
    }
}

 

posted @ 2023-05-27 16:49 huhuuu 阅读(13) 评论(0) 推荐(0) 编辑

2023年5月26日

摘要: 借用栈的思想,维护一个单调递减的栈。 阅读全文

posted @ 2023-05-26 16:35 huhuuu 阅读(13) 评论(0) 推荐(0) 编辑

2022年2月26日

摘要: 原因可能是在以前pull下来的代码自动合并失败解决办法:切换到项目文件夹中,使用git命令舍弃本地代码,远端版本覆盖本地版本(慎重)$:git fetch --all$:git reset --hard origin/master$:git fetch保留本地的更改,中止合并->重新合并->重新拉取 阅读全文

posted @ 2022-02-26 15:53 huhuuu 阅读(41) 评论(0) 推荐(0) 编辑

2021年9月8日

摘要: 有个文本文件,需要替换里面的一个词,用python来完成,我是这样写的: 1 2 3 4 5 def modify_text(): with open('test.txt', "r+") as f: read_data = f.read() f.truncate() #清空文件 f.write(re 阅读全文

posted @ 2021-09-08 17:19 huhuuu 阅读(199) 评论(0) 推荐(0) 编辑

2021年4月14日

摘要: https://www.cnblogs.com/yyds/p/6901864.html 阅读全文

posted @ 2021-04-14 20:27 huhuuu 阅读(24) 评论(0) 推荐(0) 编辑

2021年3月15日

摘要: kill -9 $(ps -ef|grep 进程名关键字|grep -v grep|awk '{print $2}') https://www.cnblogs.com/chay/p/10473091.html 阅读全文

posted @ 2021-03-15 15:39 huhuuu 阅读(471) 评论(0) 推荐(0) 编辑

2020年2月11日

摘要: python中有 try——except 的方法捕获异常,可以获取到异常的种类以及自定义异常, 但是有时候对于debug测试来说,信息不全,比如说 触发异常的具体位置在哪: import tracebacktry: num= int('abc')except Exception: traceback 阅读全文

posted @ 2020-02-11 11:39 huhuuu 阅读(1131) 评论(0) 推荐(0) 编辑

2020年1月22日

摘要: 1、 "content":"12321231","1231231" 只匹配前一个 "content":"12321231" "content":".+?" 阅读全文

posted @ 2020-01-22 10:07 huhuuu 阅读(117) 评论(0) 推荐(0) 编辑

2019年11月7日

摘要: 例子: 1 2 3 4 5 6 7 try (FileReader reader = new FileReader("data.txt")) { ... }catch (IOException io) { ... }finally{ .... } 这个括号在JDK1.7之前是没有的,是1.7的新特性 阅读全文

posted @ 2019-11-07 17:16 huhuuu 阅读(745) 评论(0) 推荐(0) 编辑

2019年6月28日

摘要: https://www.cnblogs.com/hamsterPP/p/5184491.html https://www.cnblogs.com/xiuxingzhe/p/9312929.html 阅读全文

posted @ 2019-06-28 18:07 huhuuu 阅读(124) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示