forked from wisdompeak/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db9b988
commit c64ea64
Showing
1 changed file
with
5 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
Tree/2096.Step-By-Step-Directions-From-a-Binary-Tree-Node-to-Another/Readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
### 2096.Step-By-Step-Directions-From-a-Binary-Tree-Node-to-Another | ||
|
||
本题和以往求LCA的题目不同。以往的LCA只需要求得LCA的节点本身,而这道题需要设计到路径打印。因此我们就老老实实地用递归的方法,把从root到q或者q的路径先记录出来,然后再比较得到LCA的位置。 | ||
|
||
注意此题中我们需要记录两个信息,首先是从root到p(或者q)一路上遇到的节点数值,另外是一路上的操作(L或者R)。假设两条路径dirs1和dirs2在第k个节点位置分叉(也就是LCA的位置)。根据题意,我们就将dirs1[k:]全部搞成“U”(因为从p到LCA一路都是up),再拼接上dirs2[k:]这段路径即可。 |