Clean And Efficient O(n) Time Solution
Naive approach would be to traverse every node of the tree and determine if its\' subtree is balanced.\n\nInstead, we will be traversing down to the leaves and 
Naive approach would be to traverse every node of the tree and determine if its\' subtree is balanced.\n\nInstead, we will be traversing down to the leaves and then calculating the height. This approach would give us $O(n)$ time complexity as we never solve the same problem multiple times, building the solution bottom to top using the heights calculated previously.\n\n```\n/**\n * Definition for a binary tree node.\n * type TreeNode struct {\n *     Val int\n *     Left *TreeNode\n *     Right *TreeNode\n * }\n */\n\nfunc isBalanced(root *TreeNode) bool {\n    res, _ := dfs(root)\n    return res\n}\n\nfunc dfs(root *TreeNode) (bool, int) {\n    if root == nil {\n        return true, 0\n    }\n\n    isLeftBalanced, leftHeight := dfs(root.Left)\n    isRightBalanced, rightHeight := dfs(root.Right)\n    diff := abs(leftHeight - rightHeight)\n    if isLeftBalanced && isRightBalanced && diff <= 1 {\n        return true, 1 + max(leftHeight, rightHeight)\n    }\n    return false, -1\n}\n\nfunc abs(n int) int {\n    if n < 0 {\n        return -n\n    }\n    return n\n}\n\nfunc max(a, b int) int {\n    if a > b {\n        return a\n    }\n    return b\n}\n\n```
['Tree', 'Depth-First Search', 'Binary Tree', 'Go']