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.
code gave run time because boilerplate code. Hackerrank must fix this line: " root = tree.insert(root: root, data: Int(readLine()!)!) ".
func getHeight(root: Node?) -> Int {
if root == nil {
return -1
} else {
let left = getHeight(root: root?.left)
let right = getHeight(root: root?.right)
if left > right {
return left + 1
} else {
return right + 1
}
}
}
Tree: Height of a Binary Tree
You are viewing a single comment's thread. Return to all comments →
In Swift
code gave run time because boilerplate code. Hackerrank must fix this line: " root = tree.insert(root: root, data: Int(readLine()!)!) ".