# Leetcode 543 - Diameter of binary tree

`Note:`

- It doesn’t feel like an easy question.
- Idea: Iterate each node and add its
`leftDepth`

with`rightDepth`

while comparing with`result`

. - Detail:
- If left and right subtree both exist,
`leftDepth + rightDepth + 1 + 1`

. - But if one of them doesn’t exist, we need to check we add
`1`

or`0`

, like`node.left ? 1 : 0`

.

- If left and right subtree both exist,

Given the root of a binary tree, return the length of the `diameter`

of the tree.

The `diameter`

of a binary tree is the `length`

of the longest path between any two nodes in a tree. This path may or may not pass through the root.

The length of a path between two nodes is represented by the number of edges between them.

`Question:`

`Example:`

1 | Input: root = [1,2,3,4,5] |

`Code:`

1 | /** |