力扣hot100—二叉树15题
二叉树的层序遍历、前中后序遍历、反转、求深度等操作。一般都要考虑递归方法。
2025-10-12 15:26
|
|
2025-10-17 14:35
力扣hot100—LinkedHashMap实现LRU缓存
可以用LinkedHashMap的数据结构实现;要自己手写的话,就需要维护一个哈希+双向链表的数据结构,使用双链表来维护缓存项的访问顺序。最近访问的项位于链表的头部,而最久未访问的项位于链表的尾部。 Map<Integer,MyNodes>,底层就是数组+双向链表。put操作,找出来修改值,放到最前面,找不到就新增,节点放最前面get操作就把…
2025-10-10 19:37
|
|
2025-10-10 19:38
力扣hot100—链表14题
相交链表、反转链表、回文链表、环形链表、合并链表、删除链表某个节点、排序链表、LRU等。
总结的解题核心方式一般都是设置一个哑前置节点、双指针、快慢指针。
2025-10-09 15:50
|
|
2025-10-11 19:13
剑指offer67题-No67.剪绳子
法1:动态规划 先贴个递归版本: int cutRope(int n) { // write code here if(n <= 4) return n; int res = 0; for(int i = 1; i < n; i++){ // 从i=1开始 表示第一刀剪下的长度 res = max(res, max(cutRope(n-…
2025-6-19 14:58
|
|
2025-6-19 14:58
剑指offer67题-No66.机器人的运动范围
和NO65差不多,dfs即可。 #include <vector> using namespace std; class Solution { public: int dx[4] = {1,0,-1,0}; int dy[4] = {0,1,0,-1}; int row; int col; int count; int t; int movi…
2025-6-19 14:57
|
|
2025-6-19 14:57
剑指offer67题-No65.矩阵中的路径
感觉类似BFS,可以参考acwing出现的题目:AcWing 844. 走迷宫 - AcWing 贴上上面这道题的BFS暴力模板: #include <iostream> #include <string> #include <queue> using namespace std; const int N = 105; int g…
2025-6-19 14:56
|
|
2025-6-19 14:56
剑指offer67题-No64.滑动窗口的最大值
超级重点题,感觉很经常考。 法1:优先队列用一个存储值和数组索引的pair放在优先队列里,当索引超出窗口范围,就把优先队列里的值删掉。 class Solution { public: vector<int> maxSlidingWindow(vector<int>& nums, int k) { priority_queue&…
2025-6-19 14:54
|
|
2025-6-19 14:54