-
Notifications
You must be signed in to change notification settings - Fork 0
/
No_199.cs
40 lines (34 loc) · 961 Bytes
/
No_199.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
namespace LeetCode
{
class No_199
{
public IList<int> RightSideView(TreeNode root)
{
List<int> output = new List<int>();
if (root != null)
{
Queue<TreeNode> tree = new Queue<TreeNode>();
tree.Enqueue(root);
int length = 1;
while (length != 0)
{
TreeNode cur = tree.Dequeue();
if (cur.left != null)
{
tree.Enqueue(cur.left);
}
if (cur.right != null)
{
tree.Enqueue(cur.right);
}
if (--length == 0)
{
output.Add(cur.val);
length = tree.Count;
}
}
}
return output;
}
}
}