Skip to content

Commit 83004ec

Browse files
committed
feat: 添加 LeetCode 和 AcWing 问题的解决方案及相关笔记
1 parent 70ef6e1 commit 83004ec

7 files changed

Lines changed: 247 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
从左到右 DP
2+
3+
首先判断边界条件
4+
5+
先判断 p[1] != '*'
6+
- if p[0] == '.' or p[0] == s[0]:
7+
- dp[0][0] = true
8+
9+
- else p[0] 和 p[1] 是一个整体
10+
- case1:匹配 0 个字符
11+
- case2:先匹配1 个字符,p[0] == '.' or p[0] == s[0],继续匹配后续的字符
12+
13+
```cpp
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'''
2+
Author: tkzzzzzz6
3+
Date: 2026-04-20 11:16:10
4+
LastEditors: tkzzzzzz6
5+
LastEditTime: 2026-04-20 11:24:14
6+
'''
7+
class Solution:
8+
def isMatch(self, s: str, p: str) -> bool:
9+
@cache
10+
def dfs(i:int,j:int)->bool:
11+
if j == len(p):
12+
return i == len(s)
13+
14+
is_match = i < len(s) and (p[j] == '.' or p[j] == s[i])
15+
16+
# 匹配零个或多个
17+
if j + 1 < len(p) and p[j+1] == '*':
18+
return (dfs(i,j+2) or is_match and dfs(i+1,j))
19+
20+
# s[i] 和 p[j]相匹配
21+
return is_match and dfs(i+1,j+1)
22+
23+
return dfs(0,0)
File renamed without changes.

leetcode/problems/.lcpr_data/bricks.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
{
22
"version": 1,
33
"all_bricks": {
4+
"71": {
5+
"submit_time": [
6+
1776671357
7+
],
8+
"type": 4,
9+
"review_day": [
10+
1776700800,
11+
1776960000,
12+
1777219200,
13+
1777824000,
14+
1779033600,
15+
1781798400
16+
]
17+
},
418
"82": {
519
"submit_time": [
620
1776596730
@@ -29,6 +43,22 @@
2943
1781712000
3044
]
3145
},
46+
"198": {
47+
"submit_time": [
48+
1776655972,
49+
1776656196,
50+
1776656531
51+
],
52+
"type": 4,
53+
"review_day": [
54+
1776700800,
55+
1776960000,
56+
1777219200,
57+
1777824000,
58+
1779033600,
59+
1781798400
60+
]
61+
},
3262
"347": {
3363
"submit_time": [
3464
1776593902,
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* @Author: tkzzzzzz6
3+
* @Date: 2026-04-20 10:49:58
4+
* @LastEditors: tkzzzzzz6
5+
* @LastEditTime: 2026-04-20 10:50:00
6+
*/
7+
/*
8+
* @lc app=leetcode.cn id=10 lang=cpp
9+
* @lcpr version=30204
10+
*
11+
* [10] 正则表达式匹配
12+
*/
13+
14+
15+
// @lcpr-template-start
16+
using namespace std;
17+
#include <algorithm>
18+
#include <array>
19+
#include <bitset>
20+
#include <climits>
21+
#include <deque>
22+
#include <functional>
23+
#include <iostream>
24+
#include <list>
25+
#include <queue>
26+
#include <stack>
27+
#include <tuple>
28+
#include <unordered_map>
29+
#include <unordered_set>
30+
#include <utility>
31+
#include <vector>
32+
// @lcpr-template-end
33+
// @lc code=start
34+
class Solution {
35+
public:
36+
bool isMatch(string s, string p) {
37+
38+
}
39+
};
40+
// @lc code=end
41+
42+
43+
44+
/*
45+
// @lcpr case=start
46+
// "aa"\n"a"\n
47+
// @lcpr case=end
48+
49+
// @lcpr case=start
50+
// "aa"\n"a*"\n
51+
// @lcpr case=end
52+
53+
// @lcpr case=start
54+
// "ab"\n".*"\n
55+
// @lcpr case=end
56+
57+
*/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#
2+
# @lc app=leetcode.cn id=198 lang=python3
3+
# @lcpr version=30204
4+
#
5+
# [198] 打家劫舍
6+
#
7+
8+
9+
# @lcpr-template-start
10+
11+
# @lcpr-template-end
12+
# @lc code=start
13+
class Solution:
14+
def rob(self, nums: List[int]) -> int:
15+
n = len(nums)
16+
f0 ,f1 = 0,0
17+
for i,x in enumerate(nums):
18+
fnew = f1
19+
f0,f1 = fnew,max(f0,f0+x)
20+
21+
return f1
22+
23+
return f[n+1];
24+
# @lc code=end
25+
26+
27+
28+
#
29+
# @lcpr case=start
30+
# [1,2,3,1]\n
31+
# @lcpr case=end
32+
33+
# @lcpr case=start
34+
# [2,7,9,3,1]\n
35+
# @lcpr case=end
36+
37+
#
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* @Author: tkzzzzzz6
3+
* @Date: 2026-04-20 15:13:56
4+
* @LastEditors: tkzzzzzz6
5+
* @LastEditTime: 2026-04-20 15:48:48
6+
*/
7+
/*
8+
* @lc app=leetcode.cn id=71 lang=cpp
9+
* @lcpr version=30204
10+
*
11+
* [71] 简化路径
12+
*/
13+
14+
15+
// @lcpr-template-start
16+
using namespace std;
17+
#include <algorithm>
18+
#include <array>
19+
#include <bitset>
20+
#include <climits>
21+
#include <deque>
22+
#include <functional>
23+
#include <iostream>
24+
#include <list>
25+
#include <queue>
26+
#include <tuple>
27+
#include <sstream>
28+
#include <unordered_map>
29+
#include <unordered_set>
30+
#include <utility>
31+
#include <vector>
32+
// @lcpr-template-end
33+
// @lc code=start
34+
class Solution {
35+
public:
36+
string simplifyPath(string path) {
37+
vector<string>st;
38+
39+
stringstream ss(path);
40+
string s;
41+
42+
while(getline(ss,s,'/')){
43+
if(s == "." || s.empty() )
44+
continue;
45+
if(s == ".."){
46+
if(!st.empty())st.pop_back();
47+
}
48+
else{
49+
st.push_back(s);
50+
}
51+
}
52+
53+
string res;
54+
for(auto &x:st){
55+
res += "/";
56+
res += x;
57+
}
58+
59+
return res.empty() ? "/": res;
60+
}
61+
};
62+
// @lc code=end
63+
64+
65+
66+
/*
67+
// @lcpr case=start
68+
// "/home/"\n
69+
// @lcpr case=end
70+
71+
// @lcpr case=start
72+
// "/home//foo/"\n
73+
// @lcpr case=end
74+
75+
// @lcpr case=start
76+
// "/home/user/Documents/../Pictures"\n
77+
// @lcpr case=end
78+
79+
// @lcpr case=start
80+
// "/../"\n
81+
// @lcpr case=end
82+
83+
// @lcpr case=start
84+
// "/.../a/../b/c/../d/./"\n
85+
// @lcpr case=end
86+
87+
*/

0 commit comments

Comments
 (0)