/**
?*?1.?題目非常簡(jiǎn)單,剛開(kāi)始還想著有沒(méi)有什么更好的方法污筷。不過(guò)很快就覺(jué)得遞歸就是最快的工闺。10分鐘就寫(xiě)好了,一次通過(guò)瓣蛀。
?*?2.?1ms,擊敗99.76%陆蟆;?40MB,擊敗27.34%惋增;
?*?
?*/
class?Solution?{
????public?boolean?isBalanced(TreeNode?root)?{
????????if(isBalancedHelp(root)?<?0){
????????????return?false;
????????}
????????return?true;
????}
????public?int?isBalancedHelp(TreeNode?root){
????????if(root?==?null){
????????????return?0;
????????}
????????int?leftNumber?=?isBalancedHelp(root.left);
????????int?rightNumber?=?isBalancedHelp(root.right);
????????if(leftNumber?<?0?||?rightNumber?<?0){
????????????return?-1;
????????}
????????if(Math.abs(leftNumber-rightNumber)>1){
????????????return?-1;
????????}
????????return?Math.max(leftNumber?+?1,?rightNumber+1);
????}
}