Skip to content

Commit c7a7a32

Browse files
Zanger67/leetcodeZanger67/leetcode
Zanger67/leetcode
authored and
Zanger67/leetcode
committed
Updated markdown files
1 parent f5a49c2 commit c7a7a32

10 files changed

+292
-218
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# **[LeetCode Records](https://leetcode.com/u/Zanger/)** (439 solved)
1+
# **[LeetCode Records](https://leetcode.com/u/Zanger/)** (440 solved)
22

33
> My LeetCode Profile: [Zanger](https://leetcode.com/u/Zanger/)
44
@@ -382,6 +382,7 @@ This repo is a collection of my LeetCode solutions, primarily written in Python,
382382
| 2083 | [Substrings That Begin and End With the Same Letter](<https://leetcode.com/problems/substrings-that-begin-and-end-with-the-same-letter>) | Medium | Weekly Premium | [solution](<markdowns/_2083. Substrings That Begin and End With the Same Letter.md>) | c, py |
383383
| 2086 | [Minimum Number of Food Buckets to Feed the Hamsters](<https://leetcode.com/problems/minimum-number-of-food-buckets-to-feed-the-hamsters>) | Medium | | [solution](<markdowns/_2086. Minimum Number of Food Buckets to Feed the Hamsters.md>) | java |
384384
| 2095 | [Delete the Middle Node of a Linked List](<https://leetcode.com/problems/delete-the-middle-node-of-a-linked-list>) | Medium | | [solution](<markdowns/_2095. Delete the Middle Node of a Linked List.md>) | c, java |
385+
| 2096 | [Step-By-Step Directions From a Binary Tree Node to Another](<https://leetcode.com/problems/step-by-step-directions-from-a-binary-tree-node-to-another>) | Medium | Daily | [solution](<markdowns/_2096. Step-By-Step Directions From a Binary Tree Node to Another.md>) | py |
385386
| 2130 | [Maximum Twin Sum of a Linked List](<https://leetcode.com/problems/maximum-twin-sum-of-a-linked-list>) | Medium | | [solution](<markdowns/_2130. Maximum Twin Sum of a Linked List.md>) | py |
386387
| 2149 | [Rearrange Array Elements by Sign](<https://leetcode.com/problems/rearrange-array-elements-by-sign>) | Medium | | [solution](<markdowns/_2149. Rearrange Array Elements by Sign.md>) | c, py |
387388
| 2165 | [Smallest Value of the Rearranged Number](<https://leetcode.com/problems/smallest-value-of-the-rearranged-number>) | Medium | | [solution](<markdowns/_2165. Smallest Value of the Rearranged Number.md>) | py |

markdowns/Daily_Questions.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Dates are for the date I completed the question so due to the my time zone and h
66

77
| # | Title | Level | Cats | Solution | Languages | Date Complete |
88
|-----:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------|:------------|:---------------------------------------------------------------------------------------------------|:-----------------------------|:----------------|
9+
| 2096 | [Step-By-Step Directions From a Binary Tree Node to Another](<https://leetcode.com/problems/step-by-step-directions-from-a-binary-tree-node-to-another>) | Medium | Daily | [solution](<_2096. Step-By-Step Directions From a Binary Tree Node to Another.md>) | py | Jul 16, 2024 |
910
| 2196 | [Create Binary Tree From Descriptions](<https://leetcode.com/problems/create-binary-tree-from-descriptions>) | Medium | Daily | [solution](<_2196. Create Binary Tree From Descriptions.md>) | py | Jul 15, 2024 |
1011
| 726 | [Number of Atoms](<https://leetcode.com/problems/number-of-atoms>) | Hard | Daily | [solution](<_726. Number of Atoms.md>) | py | Jul 14, 2024 |
1112
| 2751 | [Robot Collisions](<https://leetcode.com/problems/robot-collisions>) | Hard | Daily | [solution](<_2751. Robot Collisions.md>) | py | Jul 13, 2024 |

markdowns/Questions_By_Code_Length.md

+1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ Calculations are based on the code files's byte sizes.
156156
| 409 | [Longest Palindrome](<https://leetcode.com/problems/longest-palindrome>) | Easy | Daily | [solution](<_409. Longest Palindrome.md>) | c, py | Jun 04, 2024 |
157157
| 48 | [Rotate Image](<https://leetcode.com/problems/rotate-image>) | Medium | B75, N150 | [solution](<_48. Rotate Image.md>) | c, py | Jun 15, 2024 |
158158
| 2582 | [Pass the Pillow](<https://leetcode.com/problems/pass-the-pillow>) | Easy | Daily | [solution](<_2582. Pass the Pillow.md>) | c, cpp, cs, java, js, py | Jul 06, 2024 |
159+
| 2096 | [Step-By-Step Directions From a Binary Tree Node to Another](<https://leetcode.com/problems/step-by-step-directions-from-a-binary-tree-node-to-another>) | Medium | Daily | [solution](<_2096. Step-By-Step Directions From a Binary Tree Node to Another.md>) | py | Jul 16, 2024 |
159160
| 713 | [Subarray Product Less Than K](<https://leetcode.com/problems/subarray-product-less-than-k>) | Medium | | [solution](<_713. Subarray Product Less Than K.md>) | py | Jul 01, 2024 |
160161
| 1759 | [Count Number of Homogenous Substrings](<https://leetcode.com/problems/count-number-of-homogenous-substrings>) | Medium | | [solution](<_1759. Count Number of Homogenous Substrings.md>) | c, java | Jun 10, 2024 |
161162
| 676 | [Implement Magic Dictionary](<https://leetcode.com/problems/implement-magic-dictionary>) | Medium | | [solution](<_676. Implement Magic Dictionary.md>) | py | Jun 27, 2024 |

markdowns/Questions_By_Recent.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Calculations are based on the date of the first solve.
66

77
| # | Title | Level | Cats | Solution | Languages | Date Complete |
88
|-----:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------|:---------------|:---------------------------------------------------------------------------------------------------|:---------------------------------|:----------------|
9+
| 2096 | [Step-By-Step Directions From a Binary Tree Node to Another](<https://leetcode.com/problems/step-by-step-directions-from-a-binary-tree-node-to-another>) | Medium | Daily | [solution](<_2096. Step-By-Step Directions From a Binary Tree Node to Another.md>) | py | Jul 16, 2024 |
910
| 236 | [Lowest Common Ancestor of a Binary Tree](<https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree>) | Medium | B75 | [solution](<_236. Lowest Common Ancestor of a Binary Tree.md>) | py | Jul 15, 2024 |
1011
| 1740 | [Find Distance in a Binary Tree](<https://leetcode.com/problems/find-distance-in-a-binary-tree>) | Medium | Weekly Premium | [solution](<_1740. Find Distance in a Binary Tree.md>) | py | Jul 15, 2024 |
1112
| 2196 | [Create Binary Tree From Descriptions](<https://leetcode.com/problems/create-binary-tree-from-descriptions>) | Medium | Daily | [solution](<_2196. Create Binary Tree From Descriptions.md>) | py | Jul 15, 2024 |

markdowns/Topics.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
- [Array](<by_topic/Array.md>) (197 completed)
88
- [Hash Table](<by_topic/Hash Table.md>) (99 completed)
9-
- [String](<by_topic/String.md>) (96 completed)
10-
- [Depth-First Search](<by_topic/Depth-First Search.md>) (70 completed)
11-
- [Tree](<by_topic/Tree.md>) (69 completed)
12-
- [Binary Tree](<by_topic/Binary Tree.md>) (64 completed)
9+
- [String](<by_topic/String.md>) (97 completed)
10+
- [Depth-First Search](<by_topic/Depth-First Search.md>) (71 completed)
11+
- [Tree](<by_topic/Tree.md>) (70 completed)
12+
- [Binary Tree](<by_topic/Binary Tree.md>) (65 completed)
1313
- [Sorting](<by_topic/Sorting.md>) (60 completed)
1414
- [Math](<by_topic/Math.md>) (54 completed)
1515
- [Breadth-First Search](<by_topic/Breadth-First Search.md>) (48 completed)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# 2096. [Step-By-Step Directions From a Binary Tree Node to Another](<https://leetcode.com/problems/step-by-step-directions-from-a-binary-tree-node-to-another>)
2+
3+
*All prompts are owned by LeetCode. To view the prompt, click the title link above.*
4+
5+
*[Back to top](<../README.md>)*
6+
7+
------
8+
9+
> *First completed : July 16, 2024*
10+
>
11+
> *Last updated : July 16, 2024*
12+
13+
------
14+
15+
> **Related Topics** : **[String](<by_topic/String.md>), [Tree](<by_topic/Tree.md>), [Depth-First Search](<by_topic/Depth-First Search.md>), [Binary Tree](<by_topic/Binary Tree.md>)**
16+
>
17+
> **Acceptance Rate** : **48.939 %**
18+
19+
------
20+
21+
## Solutions
22+
23+
- [m2096 Daily.py](<../my-submissions/m2096 Daily.py>)
24+
### Python
25+
#### [m2096 Daily.py](<../my-submissions/m2096 Daily.py>)
26+
```Python
27+
# Definition for a binary tree node.
28+
# class TreeNode:
29+
# def __init__(self, val=0, left=None, right=None):
30+
# self.val = val
31+
# self.left = left
32+
# self.right = right
33+
class Solution:
34+
def getDirections(self, root: Optional[TreeNode], startValue: int, destValue: int) -> str:
35+
start, end = [], []
36+
37+
def dfs(curr: Optional[TreeNode], start: List[str], target: List[str], path: List[str] = []) -> None :
38+
if start and target :
39+
return
40+
41+
if curr.val == startValue :
42+
start.extend(path)
43+
if curr.val == destValue :
44+
target.extend(path)
45+
46+
if curr.left :
47+
path.append('L')
48+
dfs(curr.left, start, target, path)
49+
path.pop()
50+
if curr.right :
51+
path.append('R')
52+
dfs(curr.right, start, target, path)
53+
path.pop()
54+
55+
dfs(root, start, end)
56+
57+
shorter = min(len(start), len(end))
58+
ups = 0
59+
while ups < shorter :
60+
if start[ups] != end[ups] :
61+
break
62+
ups += 1
63+
64+
return 'U' * (len(start) - ups) + ''.join(end[ups:])
65+
```
66+

0 commit comments

Comments
 (0)