Improved Java Solution for "Balanced Binary Tree" #129
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The following is a proposed improved solution in Java for Balanced Binary Tree.
I choose to use a Java Pair (somewhat different from C# Tuples - see how I did in C# https://github.com/irlcatgirl/Leetcode-BalancedBinaryTree-CS/blob/main/Solution.cs). I think the
.getKey()
and.getValue()
does impact readability a bit although I think it's a little better than the alternative. Perhaps we could return a set or array but I'm concerned with the memory usage from that. My goal here was to maximize code readability, I'm not sure if this accomplishes that or makes the problem worse so consider this a feedback stage.Stats
Runtime: 3 ms, faster than 8.81% of Java online submissions for Balanced Binary Tree. (I don't think I can beat 3ms but if you can let me know)
Memory Usage: 45.2 MB, less than 9.73% of Java online submissions for Balanced Binary Tree. (I think memory usage is what it is, but feel free to show alternatives with a DFS).