Skip to content

Conversation

elaine-jackson
Copy link
Contributor

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).

@neetcode-gh neetcode-gh merged commit ad78c37 into neetcode-gh:main Jun 8, 2022
neetcode-gh added a commit that referenced this pull request Jul 2, 2022
Improved Java Solution for "Balanced Binary Tree"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants