You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.
4
+
5
+
According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).”
6
+
7
+
Given the following binary tree: root = [3,5,1,6,2,0,8,null,null,7,4]
8
+
9
+
10
+
11
+
12
+
Example 1:
13
+
Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1
14
+
Output: 3
15
+
Explanation: The LCA of nodes 5 and 1 is 3.
16
+
17
+
18
+
Example 2:
19
+
Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4
20
+
Output: 5
21
+
Explanation: The LCA of nodes 5 and 4 is 5, since a node can be a descendant of itself according to the LCA definition.
22
+
23
+
24
+
Note:
25
+
26
+
All of the nodes' values will be unique.
27
+
p and q are different and both values will exist in the binary tree.
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
3
+
4
+
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
5
+
6
+
How many possible unique paths are there?
7
+
8
+
9
+
Above is a 7 x 3 grid. How many possible unique paths are there?
10
+
11
+
Note: m and n will be at most 100.
12
+
13
+
Example 1:
14
+
Input: m = 3, n = 2
15
+
Output: 3
16
+
Explanation:
17
+
From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
0 commit comments