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 投票数
Article Rating
订阅评论
提醒

0 评论
最新
最旧 最多投票
内联反馈
查看所有评论