LeetCode-110

Links:https://leetcode.com/problems/balanced-binary-tree/

Given a binary tree, determine if it is height-balanced.

For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.

思路:递归深度判断即可.(需另写深度计算函数)

解法1:计算二叉树的深度

解法2:计算平衡二叉树的深度,非平衡二叉树返回-1

 

下面附上一个12ms的解法:我至今不知道为何是12ms…因为你稍微改一下格式比如去掉public下面的换行,就变成16ms了…

 

【LeetCode】110. Balanced Binary Tree
Tagged on:
0 0 vote
Article Rating
订阅
提醒
0 评论
Inline Feedbacks
View all comments