We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Tree: Height of a Binary Tree
Tree: Height of a Binary Tree
Sort by
recency
|
962 Discussions
|
Please Login in order to post a comment
C++ solution:
-1 in the base case accounts for the fact that path length = nodes - 1;
Calculates the height of a binary tree recursively. ` public static int recHeight(Node node, int counter) { // Base Case: If the node is null, return the current counter as the height if (node == null) { return counter; }
} `
Swift version seems to be broken and crashes for any tree with more than one node due to an error in reading the input here:
let t = Int(readLine()!)!
for _ in 0..
}
The problem is that the 'for' loop expects for each node data to appear on a separate line, while they all on the same line separated by commas.
`