What is bad about this? Looks pretty readable to me, good variable names (all though perhaps a bit verbose), and it's pretty much just the standard O(n) algorithm
Yeah, looks good to me. Only improvement is to stop the height difference and just use leftHeight == rightHeight instead of the ugly Math.abs and the extra variable. But that’s almost nothing.
137
u/SuperSmurfen Jun 19 '21 edited Jun 19 '21
What is bad about this? Looks pretty readable to me, good variable names (all though perhaps a bit verbose), and it's pretty much just the standard O(n) algorithm
www.geeksforgeeks.org/how-to-determine-if-a-binary-tree-is-balanced