会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
Uitachi
fresh coder
博客园
首页
新随笔
联系
订阅
管理
上一页
1
2
3
4
5
6
7
···
19
下一页
2022年3月1日
LeetCode3. 无重复字符的最长子串
摘要: 题目 分析 用滑动窗口,就是双指针来做。设 i 为串的尾指针,符合题目要求的串的左侧指针为 j ,且 i 指针向后移动时,j 指针可能不动或者向右移动。 用哈希表来存 从 j 到 i 部分的每个字符的次数,如果 i + 1 重复的话,那么冲突的一定是 位置 i 和 i + 1 部分冲突,这时 j 需
阅读全文
posted @ 2022-03-01 15:05 Uitachi
阅读(24)
评论(0)
推荐(0)
2022年2月28日
C++中unordered_map常用操作
摘要: C++中unordered_map常用操作 成员函数 1. 迭代器 begin 返回指向容器起始位置的迭代器(iterator)end 返回指向容器末尾位置的迭代器cbegin 返回指向容器起始位置的常迭代器(const_iterator)cend 返回指向容器末尾位置的常迭代器元素的键值分别是迭代
阅读全文
posted @ 2022-02-28 15:52 Uitachi
阅读(678)
评论(0)
推荐(0)
2021年3月20日
LeetCode21. 合并两个有序链表
摘要: 题目 分析 本题可以直接模拟,可以递归 代码 递归 1 class Solution { 2 public: 3 ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { 4 if(l1 == NULL) return l2; 5 if(l2 ==
阅读全文
posted @ 2021-03-20 20:55 Uitachi
阅读(35)
评论(0)
推荐(0)
LeetCode24. 两两交换链表中的节点
摘要: 题目 分析 利用哑结点方便操作。 head->n1->n2->n3->n4 交换步骤 1. n1指向n3 2. n2指向n1 3. head->next 指向n2 4. head指向n1(n3的前一个结点) 代码 1 class Solution { 2 public: 3 ListNode* sw
阅读全文
posted @ 2021-03-20 20:25 Uitachi
阅读(39)
评论(0)
推荐(0)
2021年3月19日
LeetCode2. 两数相加
摘要: 题目 分析 模拟题目 先建立哑结点,采用头插法。 代码 1 class Solution { 2 public: 3 ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { 4 ListNode *head = new ListNode(); 5
阅读全文
posted @ 2021-03-19 21:33 Uitachi
阅读(39)
评论(0)
推荐(0)
2021年3月11日
LeetCode98. 验证二叉搜索树
摘要: 题目 代码 法一、中序遍历结果保存下来,查看是否是递增序列 1 class Solution { 2 public: 3 vector<int>res; 4 void dfs(TreeNode* root){ 5 if(root == NULL) return; 6 dfs(root->left);
阅读全文
posted @ 2021-03-11 22:17 Uitachi
阅读(67)
评论(0)
推荐(0)
LeetCode654. 最大二叉树
摘要: 题目 代码 1 class Solution { 2 public: 3 TreeNode* constructMaximumBinaryTree(vector<int>& nums) { 4 //数组长度是一直接返回 5 if(nums.size() == 1) {TreeNode *root =
阅读全文
posted @ 2021-03-11 18:35 Uitachi
阅读(56)
评论(0)
推荐(0)
2021年3月10日
LeetCode105. 从前序与中序遍历序列构造二叉树
摘要: 题目 代码 1 class Solution { 2 public: 3 TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) { 4 if(preorder.size() == 0) return NULL; 5 //找根
阅读全文
posted @ 2021-03-10 22:25 Uitachi
阅读(64)
评论(0)
推荐(0)
LeetCode106. 从中序与后序遍历序列构造二叉树
摘要: 题目 代码 1 class Solution { 2 public: 3 4 TreeNode* buildTree(vector<int>& inorder, vector<int>& postorder) { 5 //第一步 6 if(postorder.size() == 0) return
阅读全文
posted @ 2021-03-10 21:55 Uitachi
阅读(74)
评论(0)
推荐(0)
LeetCode513. 找树左下角的值
摘要: 题目 代码 层次遍历(一) 1 class Solution { 2 public: 3 int getDepth(TreeNode* root){ 4 if(root == NULL) return 0; 5 return max(getDepth(root->left),getDepth(roo
阅读全文
posted @ 2021-03-10 18:27 Uitachi
阅读(66)
评论(0)
推荐(0)
上一页
1
2
3
4
5
6
7
···
19
下一页
公告