-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathTreeNode.cs
49 lines (42 loc) · 1.09 KB
/
TreeNode.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
41
42
43
44
45
46
47
48
49
/* ==============================================================================
* 功能描述:TreeNode
* 创 建 者:gz
* 创建日期:2017/4/19 12:20:32
* ==============================================================================*/
using System;
namespace Tree.TreeLib
{
/// <summary>
/// TreeNode
/// Definition for a binary tree node.
/// </summary>
public class TreeNode
{
public TreeNode(int x)
{
val = x;
}
public int val;
public TreeNode left;
public TreeNode right;
public bool isLeaf()
{
return left == null && right == null;
}
public int Height
{
get
{
if (this == null)
return 0;
return 1 + Math.Max(height(this.left), height(this.right));
}
}
private int height(TreeNode node)
{
if (node == null)
return 0;
return 1 + Math.Max(height(node.left), height(node.right));
}
}
}