C++ code with short cut
 // We definitely need to calculate the height of each node\n    // Actually when we calculate the height, we can perform the balance check at the same time\n  
     // We definitely need to calculate the height of each node\n    // Actually when we calculate the height, we can perform the balance check at the same time\n    // this help function just did this\n    class Solution {\n    private:\n        bool isBalancedTreeHelper(TreeNode* root,int&depth)\n        {\n            if(root==NULL)\n            {\n                depth = 0;\n                return true;\n            }\n            int left,right;\n            // Notice, the logic operation is shortcut\n            // once the left tree is judged to be unbalanced, then the right tree will not be judged\n            if(isBalancedTreeHelper(root->left,left) && isBalancedTreeHelper(root->right,right) && abs(left-right)<2){\n                depth = max(left,right)+1;\n                return true;\n            }\n            return false;\n        }\n    public:\n        bool isBalanced(TreeNode* root) {\n            int depth;\n            return isBalancedTreeHelper(root,depth);\n        }\n    };
[]