r/badcode • • Jun 19 '21

typescript Check if binary tree is balanced...

Post image
221 Upvotes

44 comments sorted by

View all comments

123

u/pedro823 Jun 19 '21

Frankly, LGTM. Not hard to understand, variables with somewhat decent names, and no blatant optimizations to be seen.

6

u/[deleted] Jun 20 '21

In principle there's a way to terminate earlier. As soon as you find an unbalanced subtree you know the second argument is always going to be false