Huadong Hu Blog

[LeetCode] 968. Binary Tree Cameras

Solution This problem can be reduced to Minimum Dominating Set problem in Trees. Find minimum set of vertices such that every vertex is in or adjacent to set is NP-complete in general graphs, but...

[LeetCode] 644. Maximum Average Subarray II

Solution Since the average must be> = the smallest element in the array, and <= the largest element in the array, we can perform binary search between the smallest and largest elements. Assuming that...

[LeetCode] 1273. Delete Tree Nodes

Solution Do dfs on tree and check on backtracking if sum from children to current node equals to 0, if yes, trim it and its children by return count = 0 to its parent....