MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/o3fan0/check_if_binary_tree_is_balanced/h2c7len/?context=3
r/badcode • u/MrPancholi • Jun 19 '21
44 comments sorted by
View all comments
123
Frankly, LGTM. Not hard to understand, variables with somewhat decent names, and no blatant optimizations to be seen.
22 u/SuitableDragonfly Jun 20 '21 Me too. I was sitting here wondering if I was just really stupid to not see how this is bad. 5 u/paulsmithkc 👨🏫 Jun 20 '21 This looks like awesome code to me. Well documented, good variable names, super easy to read, easy to test, and sufficiently optimized.This is a great example of where tuples work well, and how to use them in a recursive function.High five to whoever wrote the code, I'm sure they'd be be a great team member to have. 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 -62 u/MrPancholi Jun 19 '21 It does work, but I just thought that the tuple thing I did was a little weird.I suck with algorithms so I though this was pretty far form the ideal solution. 69 u/dliwespf Jun 19 '21 Since this seems to be your own code: Don't shame yourself, your code is quite alright.And additionally: You seem to try to improve your own coding style. So in my opinion you are doing well!
22
Me too. I was sitting here wondering if I was just really stupid to not see how this is bad.
5 u/paulsmithkc 👨🏫 Jun 20 '21 This looks like awesome code to me. Well documented, good variable names, super easy to read, easy to test, and sufficiently optimized.This is a great example of where tuples work well, and how to use them in a recursive function.High five to whoever wrote the code, I'm sure they'd be be a great team member to have.
5
This looks like awesome code to me. Well documented, good variable names, super easy to read, easy to test, and sufficiently optimized.
This is a great example of where tuples work well, and how to use them in a recursive function.
High five to whoever wrote the code, I'm sure they'd be be a great team member to have.
6
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
-62
It does work, but I just thought that the tuple thing I did was a little weird.I suck with algorithms so I though this was pretty far form the ideal solution.
It does work, but I just thought that the tuple thing I did was a little weird.
I suck with algorithms so I though this was pretty far form the ideal solution.
69 u/dliwespf Jun 19 '21 Since this seems to be your own code: Don't shame yourself, your code is quite alright.And additionally: You seem to try to improve your own coding style. So in my opinion you are doing well!
69
Since this seems to be your own code: Don't shame yourself, your code is quite alright.
And additionally: You seem to try to improve your own coding style. So in my opinion you are doing well!
123
u/pedro823 Jun 19 '21
Frankly, LGTM. Not hard to understand, variables with somewhat decent names, and no blatant optimizations to be seen.