Leetcode-Question-110: Balanced Binary Tree

原文链接:
https://leetcode.com/problems/balanced-binary-tree/

题目描述:

  1. Balanced Binary Tree
    Difficulty: Easy

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.

解析:

  • 自顶向下方法,时间复杂度为O(n^2)

 

  • 自底向上方法,DFS,时间复杂度为O(n).

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注