career 4.1
題目:Implement a function to check if a tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that no two leaf nodes differ in distance from the root by more than one .
我們再看 careercup 書上對於balanced的定義:a balanced tree is a tree which has no two leaf nodes differ in distance from the root by more than one .
我們可以找到一個反例,說明這個定義是錯誤的:如下圖,有2個leafs,高度差為0,但整個 tree 是unbalanced,原因是第二行的節點左右的subtree的高度不同。