08 2023 档案
摘要:class Solution { public: int longestValidParentheses(string s) { stack<int> stk; int res = 0; // start表示上一段第一次出现不合法的括号序列的右括号的位置 for(int i = 0, start =
阅读全文
摘要:根本思想就是二进制能够表示任意类型的数。 class Solution { public: double myPow(double x, int n) { // 为了防止判断n为负数取反时造成溢出 // 用long long 类型接收 long long N = n; // 记录N是否是负数 int
阅读全文
摘要:申请权限 申请js权限是一切的开始,不用多说了吧。 套用模板 对于前端小白来说,最省时间的美化方法就是套用BNDong大神的模板 github链接:https://github.com/BNDong/Cnblogs-Theme-SimpleMemory 教程官网:https://bndong.git
阅读全文
摘要:题不难,但理解思路很重要。 做法是单调队列。 如果求滑动窗口的最大值,那么必须在单调队列保持严格单调递减(只能小于,小于等于也不行),为啥不行还不是很清楚。 并且,单调队列一定存储的是数组的索引!!否则无法确定滑动窗口的开始位置以及开始时的队列存储最大值的情况。 class Solution { p
阅读全文
摘要:这两个题非常相似,但是前者较为简单,后者较难。 由于前者访问的矩阵是方阵,因此可以通过迭代去做(因为方阵每次迭代,长和宽缩水的大小是一样的,但是矩阵不可以,因为矩阵最后一次迭代,长和宽的缩水不一定一样) class Solution { public: vector<vector<int>> gen
阅读全文
摘要:方法一: 由于是有序的平衡二叉树,因此是中序。根据dfs中序迭代求得递增排序后,再反转就可求得结果。 class Solution { public: vector<int> tmp; int kthLargest(TreeNode* root, int k) { // if(root != NUL
阅读全文
摘要:本题比较重要的有两点: 1.一般认为有序的二叉搜索树,都是中序遍历。 2.中序遍历的递归顺序,得到的就是排好序的,就是链表的顺序,因此只需管遍历的过程中的链表指向即可。 class Solution { public: // pre将来指向尾节点,head指向头节点 Node *pre = null
阅读全文
摘要:dfs class Solution { public: vector<vector<int>> res; vector<int> tmp; void dfs(TreeNode *node, int target) { if(node == nullptr ) return; target -= n
阅读全文
摘要:dfs: 代码比bfs简洁一点,稍微比bfs快一点。 class Solution { private: int res = 0; int get(int x) { int ans = 0; while(x) { ans += x % 10; x /= 10; } return ans; } voi
阅读全文
摘要:力扣官方解法: class Solution { public: bool exist(vector<vector<char>>& board, string word) { int h = board.size(), w = board[0].size(); vector<vector<int>>
阅读全文