随笔分类 - leetcode算法题总结
2022年10月13日23点22分,归纳总结过程也当作复习代码思路
摘要:994. 腐烂的橘子 来自 <https://leetcode.cn/problems/rotting-oranges/> class Solution { public: // bfs int orangesRotting(vector<vector<int>>& grid) { int dx[4
阅读全文
摘要:class Solution { public: // dfs vector<vector<int>> res; vector<int> path; // 只能是全局变量 bool flag[100]; int n=0; void dfs(int u,vector<int>& nums){ if(u
阅读全文
摘要:206. 反转链表 来自 <https://leetcode.cn/problems/reverse-linked-list/> /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *n
阅读全文
摘要:21. 合并两个有序链表 来自 <https://leetcode.cn/problems/merge-two-sorted-lists/> /** * Definition for singly-linked list. * struct ListNode { * int val; * ListN
阅读全文
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) :
阅读全文
摘要:class Solution { public: // 除k取余法求二进制 (暴力) vector<int> countBits(int n) { vector<int> ans; for(int i=0;i<=n;i++){ int t=i; int count=0; while(t!=0){ i
阅读全文
摘要:/* // Definition for a Node. class Node { public: int val; Node* left; Node* right; Node* next; Node() : val(0), left(NULL), right(NULL), next(NULL) {
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), rig
阅读全文
摘要:567. 字符串的排列 来自 <https://leetcode.cn/problems/permutation-in-string/?envType=study-plan&id=suan-fa-ru-men&plan=algorithms&plan_progress=sc0sqw2> class
阅读全文
摘要:733. 图像渲染 来自 <https://leetcode.cn/problems/flood-fill/> class Solution { public: // bfs int dx[4]={-1,0,1,0}; int dy[4]={0,1,0,-1}; vector<vector<int>
阅读全文
摘要:class Solution { public: // bfs适合距离为1的情形; int n,m; int maxAreaOfIsland(vector<vector<int>>& grid) { int maxArea =0; n=grid.size(); m=grid[0].size(); v
阅读全文