PROBLEM DESCRIPTION
Given a binary tree, find its height.
SOLUTION
1
2
3
4
5
6
7
8
class Solution {
int height(Node node)
{
return node == null ? 0 : 1 + Math.max(height(node.left), height(node.right));
}
}
Given a binary tree, find its height.
1
2
3
4
5
6
7
8
class Solution {
int height(Node node)
{
return node == null ? 0 : 1 + Math.max(height(node.left), height(node.right));
}
}