Skip to content

Commit 9116541

Browse files
committed
Chapter 06 section 02, 03 comments updated.
1 parent ada7183 commit 9116541

File tree

13 files changed

+36
-9
lines changed

13 files changed

+36
-9
lines changed

06-Stack-and-Queue/Course Code (C++)/02-Recursion-and-Stack/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ using namespace std;
66
/// 144. Binary Tree Preorder Traversal
77
/// https://leetcode.com/problems/binary-tree-preorder-traversal/description/
88
/// 二叉树的前序遍历
9+
/// 时间复杂度: O(n), n为树的节点个数
10+
/// 空间复杂度: O(h), h为树的高度
911

1012
/// Definition for a binary tree node.
1113
struct TreeNode {

06-Stack-and-Queue/Course Code (C++)/02-Recursion-and-Stack/main2.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ using namespace std;
66
/// 94. Binary Tree Inorder Traversal
77
/// https://leetcode.com/problems/binary-tree-inorder-traversal/solution/
88
/// 二叉树的中序遍历
9+
/// 时间复杂度: O(n), n为树的节点个数
10+
/// 空间复杂度: O(h), h为树的高度
911

1012
/// Definition for a binary tree node.
1113
struct TreeNode {

06-Stack-and-Queue/Course Code (C++)/02-Recursion-and-Stack/main3.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ using namespace std;
66
/// 145. Binary Tree Postorder Traversal
77
/// https://leetcode.com/problems/binary-tree-postorder-traversal/description/
88
/// 二叉树的后序遍历
9+
/// 时间复杂度: O(n), n为树的节点个数
10+
/// 空间复杂度: O(h), h为树的高度
911

1012
/// Definition for a binary tree node.
1113
struct TreeNode {

06-Stack-and-Queue/Course Code (C++)/03-Non-Recursive-Implementation-of-a-Recursive-Algorithm/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ using namespace std;
88
/// 144. Binary Tree Preorder Traversal
99
/// https://leetcode.com/problems/binary-tree-preorder-traversal/description/
1010
/// 非递归的二叉树的前序遍历
11+
/// 时间复杂度: O(n), n为树的节点个数
12+
/// 空间复杂度: O(h), h为树的高度
1113

1214
/// Definition for a binary tree node.
1315
struct TreeNode {

06-Stack-and-Queue/Course Code (C++)/03-Non-Recursive-Implementation-of-a-Recursive-Algorithm/main2.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ using namespace std;
66
/// 94. Binary Tree Inorder Traversal
77
/// https://leetcode.com/problems/binary-tree-inorder-traversal/solution/
88
/// 非递归的二叉树的中序遍历
9+
/// 时间复杂度: O(n), n为树的节点个数
10+
/// 空间复杂度: O(h), h为树的高度
911

1012
/// Definition for a binary tree node.
1113
struct TreeNode {

06-Stack-and-Queue/Course Code (C++)/03-Non-Recursive-Implementation-of-a-Recursive-Algorithm/main3.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ using namespace std;
77
/// 145. Binary Tree Postorder Traversal
88
/// https://leetcode.com/problems/binary-tree-postorder-traversal/description/
99
/// 非递归的二叉树的后序遍历
10+
/// 时间复杂度: O(n), n为树的节点个数
11+
/// 空间复杂度: O(h), h为树的高度
1012

1113
/// Definition for a binary tree node.
1214
struct TreeNode {

06-Stack-and-Queue/Course Code (C++)/04-Binary-Tree-Level-Order-Traversal/main.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
using namespace std;
77

8+
/// 102. Binary Tree Level Order Traversal
9+
/// https://leetcode.com/problems/binary-tree-level-order-traversal/description/
10+
811
/// Definition for a binary tree node.
912
struct TreeNode {
1013
int val;
@@ -22,23 +25,23 @@ class Solution {
2225
return res;
2326

2427
queue<pair<TreeNode*,int>> q;
25-
q.push( make_pair( root , 0 ) );
28+
q.push(make_pair(root, 0 ));
2629

27-
while( !q.empty() ){
30+
while(!q.empty()){
2831

2932
TreeNode* node = q.front().first;
3033
int level = q.front().second;
3134
q.pop();
3235

33-
if( level == res.size() )
34-
res.push_back( vector<int>() );
36+
if(level == res.size())
37+
res.push_back(vector<int>());
3538
assert( level < res.size() );
3639

37-
res[level].push_back( node->val );
38-
if( node->left )
39-
q.push( make_pair(node->left, level + 1 ) );
40-
if( node->right )
41-
q.push( make_pair(node->right, level + 1 ) );
40+
res[level].push_back(node->val);
41+
if(node->left)
42+
q.push(make_pair(node->left, level + 1 ));
43+
if(node->right)
44+
q.push(make_pair(node->right, level + 1 ));
4245
}
4346

4447
return res;

06-Stack-and-Queue/Course Code (Java)/02-Recursion-and-Stack/src/Solution094.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
/// 94. Binary Tree Inorder Traversal
55
/// https://leetcode.com/problems/binary-tree-inorder-traversal/solution/
66
/// 二叉树的中序遍历
7+
/// 时间复杂度: O(n), n为树的节点个数
8+
/// 空间复杂度: O(h), h为树的高度
79
public class Solution094 {
810

911
// Definition for a binary tree node.

06-Stack-and-Queue/Course Code (Java)/02-Recursion-and-Stack/src/Solution144.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
/// 144. Binary Tree Preorder Traversal
55
/// https://leetcode.com/problems/binary-tree-preorder-traversal/description/
66
/// 二叉树的前序遍历
7+
/// 时间复杂度: O(n), n为树的节点个数
8+
/// 空间复杂度: O(h), h为树的高度
79
public class Solution144 {
810

911
// Definition for a binary tree node.

06-Stack-and-Queue/Course Code (Java)/02-Recursion-and-Stack/src/Solution145.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
/// 145. Binary Tree Postorder Traversal
55
/// https://leetcode.com/problems/binary-tree-postorder-traversal/description/
66
/// 二叉树的后序遍历
7+
/// 时间复杂度: O(n), n为树的节点个数
8+
/// 空间复杂度: O(h), h为树的高度
79
public class Solution145 {
810

911
// Definition for a binary tree node.

06-Stack-and-Queue/Course Code (Java)/03-Non-Recursive-Implementation-of-a-Recursive-Algorithm/src/Solution094.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
/// 94. Binary Tree Inorder Traversal
66
/// https://leetcode.com/problems/binary-tree-inorder-traversal/solution/
77
/// 非递归二叉树的中序遍历
8+
/// 时间复杂度: O(n), n为树的节点个数
9+
/// 空间复杂度: O(h), h为树的高度
810
public class Solution094 {
911

1012
// Definition for a binary tree node.

06-Stack-and-Queue/Course Code (Java)/03-Non-Recursive-Implementation-of-a-Recursive-Algorithm/src/Solution144.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
/// 144. Binary Tree Preorder Traversal
66
/// https://leetcode.com/problems/binary-tree-preorder-traversal/description/
77
/// 非递归二叉树的前序遍历
8+
/// 时间复杂度: O(n), n为树的节点个数
9+
/// 空间复杂度: O(h), h为树的高度
810
public class Solution144 {
911

1012
// Definition for a binary tree node.

06-Stack-and-Queue/Course Code (Java)/03-Non-Recursive-Implementation-of-a-Recursive-Algorithm/src/Solution145.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
/// 145. Binary Tree Postorder Traversal
66
/// https://leetcode.com/problems/binary-tree-postorder-traversal/description/
77
/// 非递归的二叉树的后序遍历
8+
/// 时间复杂度: O(n), n为树的节点个数
9+
/// 空间复杂度: O(h), h为树的高度
810
public class Solution145 {
911

1012
// Definition for a binary tree node.

0 commit comments

Comments
 (0)