The diameter of a tree is the number of nodes on the longest path between two leaves in the tree. The diagram below shows two trees each with diameter nine, the leaves that form the ends of a longest path are colored (note that there may be more than one path in tree of same diameter).
Input : 1
/ \
2 3
/ \
4 5
Output : 4
Input : 1
/ \
2 3
/ \ . \
4 5 . 6
Output : 5