posts - 501,comments - 0,views - 23683

随笔分类 -  LeetCode

1 2 3 下一页
LeetCode合并两个有序数组(逆向双指针)
摘要:原题解 题目 解法 逆向双指针 算法数学验证 是先假设符合空间要求,化简公式得到的p2正好取值在[0, n],符合要求 代码 public void merge(int[] nums1, int m, int[] nums2, int n) { int a = m - 1, b = n - 1, c 阅读全文
posted @ 2024-04-04 00:43 垂序葎草 阅读(13) 评论(0) 推荐(0) 编辑
LeetCode 146. LRU 缓存(hash/手写链表)
摘要:> 20230711第一次学习 20230713顺利通过 [原题解](https://leetcode.cn/problems/lru-cache/solutions/259678/lruhuan-cun-ji-zhi-by-leetcode-solution/) ###题目 ![](https:/ 阅读全文
posted @ 2023-07-11 15:46 垂序葎草 阅读(15) 评论(0) 推荐(0) 编辑
LeetCode 152. 乘积最大子数组
摘要:20230426 顺利通过 原题解 ###题目 约束 ###题解 class Solution { public: int maxProduct(vector<int>& nums) { int maxF = nums[0], minF = nums[0], ans = nums[0]; for ( 阅读全文
posted @ 2023-04-26 11:56 垂序葎草 阅读(14) 评论(0) 推荐(0) 编辑
LeetCode 148. 排序链表
摘要:20230426 顺利通过 前置题目 21. 合并两个有序链表 原题解 ###题目 约束 ###题解 ####方法一 class Solution { public: ListNode* sortList(ListNode* head) { return sortList(head, nullptr 阅读全文
posted @ 2023-04-25 00:36 垂序葎草 阅读(12) 评论(0) 推荐(0) 编辑
LeetCode 169. 多数元素(/hash sort 随机化 分治 Boyer-Moore 投票算法)
摘要:原题解 ###题目 约束 ###题解 ####方法一:哈希表 class Solution { public: int majorityElement(vector<int>& nums) { unordered_map<int, int> counts; int majority = 0, cnt 阅读全文
posted @ 2023-03-24 03:08 垂序葎草 阅读(21) 评论(0) 推荐(0) 编辑
LeetCode 160. 相交链表()
摘要:20230321 顺利通过 20230411 顺利通过 原题解 ###题目 约束 ###题解 ####方法一 class Solution { public: ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { unor 阅读全文
posted @ 2023-03-21 02:29 垂序葎草 阅读(9) 评论(0) 推荐(0) 编辑
LeetCode 142. 环形链表 II()
摘要:20230320 顺利通过 20230410 和前一题没啥区别 原题解 ###题目 约束 ###题解 ####解法一 class Solution { public: ListNode *detectCycle(ListNode *head) { unordered_set<ListNode *> 阅读全文
posted @ 2023-03-19 03:03 垂序葎草 阅读(57) 评论(0) 推荐(0) 编辑
LeetCode 141. 环形链表(/)
摘要:20230319 顺利通过 20230410 毫无思路 原题解 ###题目 约束 ###题解 ####方法一 class Solution { public: bool hasCycle(ListNode *head) { unordered_set<ListNode*> seen; while ( 阅读全文
posted @ 2023-03-19 02:55 垂序葎草 阅读(295) 评论(0) 推荐(0) 编辑
LeetCode 139. 单词拆分(/dp)
摘要:20230317 顺利通过 20230319 顺利通过 20230408 思路没记住 原题解 ###题目 约束 ###题解 class Solution { public: bool wordBreak(string s, vector<string>& wordDict) { auto wordD 阅读全文
posted @ 2023-03-17 02:29 垂序葎草 阅读(15) 评论(0) 推荐(0) 编辑
LeetCode 136. 只出现一次的数字(/思维 异或)
摘要:20230317 顺利通过 20230319 顺利通过 20230406 顺利通过 原题解 ###题目 约束 ###题解 class Solution { public: int singleNumber(vector<int>& nums) { int ret = 0; for (auto e: 阅读全文
posted @ 2023-03-17 02:25 垂序葎草 阅读(14) 评论(0) 推荐(0) 编辑
LeetCode 128. 最长连续序列(/)
摘要:20230317 顺利通过 20230319 顺利通过 20230403 if(!hashset.count(h - 1)) 原题解 ###题目 约束 ###题解 class Solution { public: int longestConsecutive(vector<int>& nums) { 阅读全文
posted @ 2023-03-16 02:47 垂序葎草 阅读(190) 评论(0) 推荐(0) 编辑
LeetCode 124. 二叉树中的最大路径和(/)
摘要:20230317 顺利通过 20230319 顺利通过 20230403 ans = max(ans, left + right + root->val); return max(left, right) + root->val; ans = -0x3f3f3f3f; 原题解 ###题目 约束 ## 阅读全文
posted @ 2023-03-16 02:24 垂序葎草 阅读(189) 评论(0) 推荐(0) 编辑
LeetCode 121. 买卖股票的最佳时机(/)
摘要:20230316 顺利通过 20230317 顺利通过 20230319 顺利通过 20230403 顺利通过 原题解 ###题目 约束 ###题解 ####方法一 class Solution { public: int maxProfit(vector<int>& prices) { int n 阅读全文
posted @ 2023-03-16 02:11 垂序葎草 阅读(10) 评论(0) 推荐(0) 编辑
LeetCode 114. 二叉树展开为链表(/)
摘要:20230317 顺利通过 20230319 顺利通过 20230403 顺利通过 原题解 ###题目 约束 ###题解 ####方法一 递归 class Solution { public: void flatten(TreeNode* root) { vector<TreeNode*> l; p 阅读全文
posted @ 2023-03-15 21:56 垂序葎草 阅读(251) 评论(0) 推荐(0) 编辑
LeetCode 104. 二叉树的最大深度(/dfs)
摘要:20230312 顺利通过 20230315 顺利通过 20230403 顺利通过 原题解 ###题目 约束 ###题解 ####解法一 class Solution { public: int maxDepth(TreeNode* root) { if (root == nullptr) retu 阅读全文
posted @ 2023-03-08 19:22 垂序葎草 阅读(12) 评论(0) 推荐(0) 编辑
LeetCode 102. 二叉树的层序遍历(/bfs)
摘要:20230403 !root ans.back() 原题解 题目 约束 ###题解 class Solution { public: vector<vector<int>> levelOrder(TreeNode* root) { vector <vector <int>> ret; if (!ro 阅读全文
posted @ 2023-03-08 00:21 垂序葎草 阅读(16) 评论(0) 推荐(0) 编辑
queue
摘要:来自我以前找的整理在doc上面的知识,来源已经不可考究了。 queue 和 stack 有一些成员函数相似,但在一些情况下,工作方式有些不同: front():返回 queue 中第一个元素的引用。如果 queue 是常量,就返回一个常引用;如果 queue 为空,返回值是未定义的。 back(): 阅读全文
posted @ 2023-03-08 00:16 垂序葎草 阅读(160) 评论(0) 推荐(0) 编辑
LeetCode 101. 对称二叉树(/dfs)
摘要:20230312 顺利通过 20230315 顺利通过 20230403 顺利通过 原题解 ###题目 约束 ###题解 ####解法一 class Solution { public: bool check(TreeNode *p, TreeNode *q) { if (!p && !q) ret 阅读全文
posted @ 2023-03-07 00:28 垂序葎草 阅读(13) 评论(0) 推荐(0) 编辑
LeetCode 98. 验证二叉搜索树(/dfs)
摘要:20230315 顺利通过 20230403 root == nullptr && LONG_MIN, LONG_MAX 原题解 ###题目 约束 ###题解 ####解法一 class Solution { public: bool helper(TreeNode* root, long long 阅读全文
posted @ 2023-03-07 00:20 垂序葎草 阅读(12) 评论(0) 推荐(0) 编辑
LeetCode 96. 不同的二叉搜索树(/dp)
摘要:20230306 顺利通过 20230312 顺利通过 20230315 顺利通过 原题解 ###题目 约束 ###题解 ####方法一 class Solution { public: int numTrees(int n) { vector<int> G(n + 1, 0); G[0] = 1; 阅读全文
posted @ 2023-03-05 22:20 垂序葎草 阅读(12) 评论(0) 推荐(0) 编辑

1 2 3 下一页
< 2025年2月 >
26 27 28 29 30 31 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 1
2 3 4 5 6 7 8

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