The reference code is broken.

  • -1

    Try this test case:


          /     \
         2       3
        / \     /
       4   5   6

    Is this tree balanced? Per the reference code/test, yes, it is.

  • 1

    For the people negging this thread: Why don't you drop a line and explain your point?

  • 1

    depth of the two subtrees of every node never differ by more than 1

    I think the wording of the question is bad which is making this confusing as the definition of a tree depth is:

    The depth of a node is the number of edges from the node to the tree's root node.

    But the question actually wants height-balanced, so you could suggest an edit to the question.

    (For the example you provided, it's definitely height balanced.)

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.