![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode刷题笔记
文章平均质量分 54
瑾修
人生苦短,何不一试?
展开
-
【leetcode hot 100】【8】15. 三数之和
【leetcode hot 100】【8】15. 三数之和原创 2023-04-25 09:18:23 · 216 阅读 · 0 评论 -
【leetcode hot 100】【7】11. 盛最多水的容器
【leetcode hot 100】【7】11. 盛最多水的容器原创 2023-04-18 09:16:17 · 150 阅读 · 0 评论 -
【leetcode hot 100】【6】10. 正则表达式匹配
(2) 如果p[j-1]与s[i]匹配,那么p[j-1]和p[j]这两个字符可以匹配多次或零次,此时有dp[i][j]=dp[i][j-2](匹配零次)或dp[i-1][j](匹配多次)。如果p[j]是一个字母,则需要判断s[i]和p[j]是否相等,如果相等,则有dp[i][j]=dp[i-1][j-1],否则dp[i][j]=false。(1) 如果p[j-1]与s[i]不匹配,那么p[j-1]和p[j]这两个字符只能匹配零次,此时有dp[i][j]=dp[i][j-2]。‘)任意字符(’.')。原创 2023-04-14 09:25:40 · 350 阅读 · 0 评论 -
【leetcode hot 100】【5】5. 最长回文子串
当 s[i]=s[j] 时,如果 dp[i+1][j-1]=true,则 dp[i][j]=true。因为只有当 i+1 到 j-1 的子串是回文串,并且 s[i]=s[j] 时,i 到 j 的子串才是回文串。具体来说,如果 dp[i][j]=true 且 j-i+1>len,则更新最长回文子串的位置和长度。定义状态 dp[i][j] 表示字符串 s 从 i 到 j 是否为回文串,是则为 true,不是则为 false。= s[j] 时,dp[i][j]=false。输入:s = “cbbd”原创 2023-04-13 09:10:48 · 378 阅读 · 0 评论 -
【leetcode hot 100】【4】4. 寻找两个正序数组的中位数
【leetcode hot 100】【4】4. 寻找两个正序数组的中位数原创 2023-04-04 09:33:28 · 251 阅读 · 0 评论 -
【leetcode hot 100】【3】3. 无重复字符的最长子串 【c++ rust go】
【leetcode hot 100】【3】3. 无重复字符的最长子串 【c++ rust go】原创 2023-03-02 08:33:14 · 208 阅读 · 1 评论 -
【leetcode hot 100】【2】2. 两数相加 【c++ rust go】
【leetcode hot 100】【2】2. 两数相加 【c++ rust go】原创 2023-03-01 08:38:39 · 227 阅读 · 0 评论 -
【leetcode hot 100】【1】1. 两数之和 【c++ rust go】
1. 两数之和 【c++ rust go】原创 2023-02-27 09:44:40 · 169 阅读 · 0 评论 -
【leetcode】2357. 使数组中所有元素都等于零(结合chatGPT版本答案)
chatGPT还需要努力来写出更高效的代码。【leetcode】2357. 使数组中所有元素都等于零(结合chatGPT版本答案)原创 2023-02-24 13:15:35 · 498 阅读 · 0 评论 -
leetcode算法杂选
string的splitstd::vector<std::string> s_split(const std::string& in, const std::string& delim) { std::regex re{ delim }; return std::vector<std::string> { std::sregex_token_iterator(in.begin(), in.end(), re, -1), std::sr原创 2021-04-07 18:31:25 · 86 阅读 · 0 评论 -
二分法(leetcode笔记)
题目示例一74. 搜索二维矩阵代码bool searchMatrix(vector<vector<int>>& matrix, int target) { int m = matrix.size(), n = matrix[0].size(); int l = 0, r = m*n-1; if( matrix[0][0] == target || target == matrix[m-1][n-1] ) return true; if(原创 2021-03-18 12:41:43 · 129 阅读 · 0 评论 -
优先队列(leetcode笔记)
1792. 最大平均通过率有的题似乎只能用优先队列做,其他方法都会超时。比如上面这道。因为之前优先队列做得少,吃了大亏。数据类型包含两个数的,优先使用pair,而非vector。pairclass Solution {public: double maxAverageRatio(vector<vector<int>>& classes, int extraStudents) { auto cmp = [](const pair<in原创 2021-03-15 13:02:04 · 216 阅读 · 0 评论