Back to course home
0% completed
Vote For New Content
Would you mind comparing this problem and LeetCode's 543 ?
Alan Lo
Aug 4, 2022
Would you mind comparing this problem and LeetCode's 543 ? https://leetcode.com/problems/diameter-of-binary-tree/
0
0
Comments
Comments
Design Gurus3 years ago
The diameter is calculated by counting the number of nodes of the longest path.
The LC problem, calculates the diameter by counting the number of edges.
Also, we assumed:
You can always assume that there are at least two leaf nodes in the given tree.
S
Sheraz Khan3 years ago
I would use a custom return object with two properties (1 that stores Diameter and another that stores the depth) and avoid the global variable.
M
Mikhail Putilov3 years ago
Ofc, Sheraz, that is as well an option. However it will impact performance by allocating N additional objects on the heap.
On this page