Skip to content

Commit 522136b

Browse files
committed
refine the file name and the problem description comment haoel#172
1 parent 8efd632 commit 522136b

File tree

2 files changed

+37
-25
lines changed

2 files changed

+37
-25
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ LeetCode
1010
|---| ----- | -------- | ---------- |
1111
|1030|[Matrix Cells in Distance Order](https://leetcode.com/problems/matrix-cells-in-distance-order/) | [C++](./algorithms/cpp/matrixCellsInDistanceOrder/MatrixCellsInDistanceOrder.cpp)|Easy|
1212
|1029|[Two City Scheduling](https://leetcode.com/problems/two-city-scheduling/) | [C++](./algorithms/cpp/twoCityScheduling/TwoCityScheduling.cpp)|Easy|
13+
|1028|[Recover a Tree From Preorder Traversal](https://leetcode.com/problems/recover-a-tree-from-preorder-traversal/) | [C++](./algorithms/cpp/recoverATreeFromPreorderTraversal/recoverATreeFromPreorderTraversal.cpp)|Hard|
1314
|993|[Cousins in Binary Tree](https://leetcode.com/problems/cousins-in-binary-tree/) | [C++](./algorithms/cpp/cousinsInBinaryTree/CousinsInBinaryTree.cpp)|Easy|
1415
|991|[Broken Calculator](https://leetcode.com/problems/broken-calculator/) | [C++](./algorithms/cpp/brokenCalculator/BrokenCalculator.cpp)|Medium|
1516
|990|[Satisfiability of Equality Equations](https://leetcode.com/problems/satisfiability-of-equality-equations/) | [C++](./algorithms/cpp/satisfiabilityOfEqualityEquations/SatisfiabilityOfEqualityEquations.cpp)|Medium|

Diff for: algorithms/cpp/recoverBinarySearchTree/recoverTreeFromPreorderTraversal.cpp renamed to algorithms/cpp/recoverATreeFromPreorderTraversal/recoverATreeFromPreorderTraversal.cpp

+36-25
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
1+
// Source : https://leetcode.com/problems/recover-a-tree-from-preorder-traversal/
2+
// Author : Ahmed Morsy
3+
// Date : 2019-05-29
14
// source : https://leetcode.com/problems/recover-a-tree-from-preorder-traversal/
2-
// Author Ahmed Morsy
3-
// Date : 2019-5-19
4-
5-
/**********************************************************************************
6-
*We run a preorder depth first search on the root of a binary tree.
7-
*At each node in this traversal, we output D dashes (where D is the depth of this node),
8-
*then we output the value of this node.
9-
*(If the depth of a node is D, the depth of its immediate child is D+1.The depth of the root node is 0.)
10-
*If a node has only one child, that child is guaranteed to be the left child.
11-
*Given the output S of this traversal, recover the tree and return its root.
12-
13-
* Input: "1-2--3--4-5--6--7"
14-
* Output: [1,2,5,3,4,6,7]
15-
16-
* Proposed Solution
17-
-----------------
18-
1. for each node in the input save its depth and value
19-
2. start a stack with the root node pushed onto it
20-
21-
IF the following node has the root's depth + 1 and the root has less than 2 children then this node
22-
is a child for this root. Add it to the stack.
23-
24-
ELSE then pop the current node from the stack.
25-
26-
**********************************************************************************/
5+
/*****************************************************************************************************
6+
*
7+
* We run a preorder depth first search on the root of a binary tree.
8+
*
9+
* At each node in this traversal, we output D dashes (where D is the depth of this node), then we
10+
* output the value of this node. (If the depth of a node is D, the depth of its immediate child is
11+
* D+1. The depth of the root node is 0.)
12+
*
13+
* If a node has only one child, that child is guaranteed to be the left child.
14+
*
15+
* Given the output S of this traversal, recover the tree and return its root.
16+
*
17+
* Example 1:
18+
*
19+
* Input: "1-2--3--4-5--6--7"
20+
* Output: [1,2,5,3,4,6,7]
21+
*
22+
* Example 2:
23+
*
24+
* Input: "1-2--3---4-5--6---7"
25+
* Output: [1,2,5,3,null,6,null,4,null,7]
26+
*
27+
* Example 3:
28+
*
29+
* Input: "1-401--349---90--88"
30+
* Output: [1,401,null,349,88,90]
31+
*
32+
* Note:
33+
*
34+
* The number of nodes in the original tree is between 1 and 1000.
35+
* Each node will have a value between 1 and 10^9.
36+
*
37+
******************************************************************************************************/
2738

2839
/* Definition for a binary tree node.
2940
struct TreeNode {

0 commit comments

Comments
 (0)