Skip to content

Commit 50b573a

Browse files
Merge pull request youngyangyang04#846 from Jerry-306/patch-37
解决算法模板C++代码没有样式问题
2 parents 46a88c3 + 5c69042 commit 50b573a

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

problems/算法模板.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
## 二分查找法
1010

11-
```
11+
```CPP
1212
class Solution {
1313
public:
1414
int searchInsert(vector<int>& nums, int target) {
@@ -33,7 +33,7 @@ public:
3333
3434
## KMP
3535
36-
```
36+
```CPP
3737
void kmp(int* next, const string& s){
3838
next[0] = -1;
3939
int j = -1;
@@ -53,7 +53,7 @@ void kmp(int* next, const string& s){
5353

5454
二叉树的定义:
5555

56-
```
56+
```CPP
5757
struct TreeNode {
5858
int val;
5959
TreeNode *left;
@@ -65,7 +65,7 @@ struct TreeNode {
6565
### 深度优先遍历(递归)
6666
6767
前序遍历(中左右)
68-
```
68+
```CPP
6969
void traversal(TreeNode* cur, vector<int>& vec) {
7070
if (cur == NULL) return;
7171
vec.push_back(cur->val); // 中 ,同时也是处理节点逻辑的地方
@@ -74,7 +74,7 @@ void traversal(TreeNode* cur, vector<int>& vec) {
7474
}
7575
```
7676
中序遍历(左中右)
77-
```
77+
```CPP
7878
void traversal(TreeNode* cur, vector<int>& vec) {
7979
if (cur == NULL) return;
8080
traversal(cur->left, vec); // 左
@@ -83,7 +83,7 @@ void traversal(TreeNode* cur, vector<int>& vec) {
8383
}
8484
```
8585
后序遍历(左右中)
86-
```
86+
```CPP
8787
void traversal(TreeNode* cur, vector<int>& vec) {
8888
if (cur == NULL) return;
8989
traversal(cur->left, vec); // 左
@@ -97,7 +97,7 @@ void traversal(TreeNode* cur, vector<int>& vec) {
9797
相关题解:[0094.二叉树的中序遍历](https://github.com/youngyangyang04/leetcode/blob/master/problems/0094.二叉树的中序遍历.md)
9898

9999
前序遍历(中左右)
100-
```
100+
```CPP
101101
vector<int> preorderTraversal(TreeNode* root) {
102102
vector<int> result;
103103
stack<TreeNode*> st;
@@ -123,7 +123,7 @@ vector<int> preorderTraversal(TreeNode* root) {
123123
```
124124
125125
中序遍历(左中右)
126-
```
126+
```CPP
127127
vector<int> inorderTraversal(TreeNode* root) {
128128
vector<int> result; // 存放中序遍历的元素
129129
stack<TreeNode*> st;
@@ -148,7 +148,7 @@ vector<int> inorderTraversal(TreeNode* root) {
148148
```
149149

150150
后序遍历(左右中)
151-
```
151+
```CPP
152152
vector<int> postorderTraversal(TreeNode* root) {
153153
vector<int> result;
154154
stack<TreeNode*> st;
@@ -176,7 +176,7 @@ vector<int> postorderTraversal(TreeNode* root) {
176176
177177
相关题解:[0102.二叉树的层序遍历](https://programmercarl.com/0102.二叉树的层序遍历.html)
178178
179-
```
179+
```CPP
180180
vector<vector<int>> levelOrder(TreeNode* root) {
181181
queue<TreeNode*> que;
182182
if (root != NULL) que.push(root);
@@ -212,7 +212,7 @@ vector<vector<int>> levelOrder(TreeNode* root) {
212212

213213
### 二叉树深度
214214

215-
```
215+
```CPP
216216
int getDepth(TreeNode* node) {
217217
if (node == NULL) return 0;
218218
return 1 + max(getDepth(node->left), getDepth(node->right));
@@ -221,15 +221,15 @@ int getDepth(TreeNode* node) {
221221
222222
### 二叉树节点数量
223223
224-
```
224+
```CPP
225225
int countNodes(TreeNode* root) {
226226
if (root == NULL) return 0;
227227
return 1 + countNodes(root->left) + countNodes(root->right);
228228
}
229229
```
230230

231231
## 回溯算法
232-
```
232+
```CPP
233233
void backtracking(参数) {
234234
if (终止条件) {
235235
存放结果;
@@ -247,7 +247,7 @@ void backtracking(参数) {
247247
248248
## 并查集
249249
250-
```
250+
```CPP
251251
int n = 1005; // 更具题意而定
252252
int father[1005];
253253

0 commit comments

Comments
 (0)