This article illustrates the concepts of inheritance vs. composition in Java. It first shows an example of inheritance, and then shows how to improve the inheritance design by using composition. How to choose between them is summarized at the end.
LeetCode – Closest Binary Search Tree Value (Java)
Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target. Java Solution 1 – Recursion Recursively traverse down the root. When target is less than root, go left; when target is greater than root, go right. public class Solution { int goal; double … Read more