Skip to content

Commit a41d1ff

Browse files
committed
https://leetcode.com/problems/binary-tree-right-side-view/
1 parent 66e4328 commit a41d1ff

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

LeetCodeSolutions/ArrayAndString/Rotate Array.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private void Helper(int[] arry, int start, int end)
3838
}
3939

4040
[Test(Description = "https://leetcode.com/problems/rotate-array/")]
41-
[Category("Easy")]
41+
[Category("Medium")]
4242
[Category("LeetCode")]
4343
[Category("Rotate Array")]
4444
[TestCaseSource(nameof(Input))]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
namespace LeetCode.MediumProblems;
2+
3+
public class BinaryTreeRightSideView
4+
{
5+
public IList<int> RightSideView(TreeNode root) {
6+
var dict = new Dictionary<int, int>();
7+
_Helper(root, 1, dict);
8+
return dict.Values.ToList();
9+
}
10+
11+
private void _Helper(TreeNode node, int depth, Dictionary<int, int> result )
12+
{
13+
if (node != null)
14+
{
15+
result[depth] = node.val;
16+
_Helper(node.left, depth + 1, result );
17+
_Helper(node.right, depth + 1, result );
18+
}
19+
}
20+
21+
[Test(Description = "https://leetcode.com/problems/binary-tree-right-side-view/")]
22+
[Category("Medium")]
23+
[Category("LeetCode")]
24+
[Category("Binary Tree Right Side View")]
25+
[TestCaseSource(nameof(Input))]
26+
[Category("Binary Tree BFS")]
27+
[Category("TopInterview")]
28+
public void Test1((List<int> Output, int?[] Input) item)
29+
{
30+
var response = RightSideView(item.Input.ToTreeNode());
31+
Assert.That(response, Is.EqualTo(item.Output));
32+
}
33+
34+
public static IEnumerable<(List<int> Output, int?[] Input)> Input =>
35+
new List<(List<int> Output, int?[] Input)>()
36+
{
37+
([1,3,4], [1,2,3,null,5,null,4]),
38+
([1,3,4, 5], [1,2,3,4,null,null,null,5]),
39+
};
40+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ The Top Interview 150 collection on Leetcode is a curated set of 150 interview q
134134
| 80 | Count Complete Tree Nodes | Easy ||
135135
| 81 | Lowest Common Ancestor of a Binary Tree | Medium | |
136136
| <br> Binary Tree BFS<br> | | | |
137-
| 8282 | Binary Tree Right Side View | Medium | |
137+
| 199 | Binary Tree Right Side View | Medium | |
138138
| 83 | Average of Levels in Binary Tree | Easy ||
139139
| 84 | Binary Tree Level Order Traversal | Medium | |
140140
| 85 | Binary Tree Zigzag Level Order Traversal | Medium | |

0 commit comments

Comments
 (0)