Recursion and Stack memory
When I was thinking about the problem Validate Binary Search Tree, my code runs like this: 12345678910111213141516171819public boolean isValidBST(TreeNode root) { TreeNode previous = null;
When I was thinking about the problem Validate Binary Search Tree, my code runs like this: 12345678910111213141516171819public boolean isValidBST(TreeNode root) { TreeNode previous = null;
When doing LeetCode problems, some corner cases should be considered when traversing through the tree, otherwise unexpected errors shall appear. Examples:Symmetric TreeSame Tree The following code tak
Let’s think about this problem: Sum Root to Leaf Numbers. A general solution is like below:123456789101112131415161718192021222324252627282930313233public int sumNumbers(TreeNode root) { if (
Imagine we need to compress a string “1111422311” into “4114221321”, which means “four ones, one four, two twos, one three, two ones”. Here is the implementation for this functionality:123456789101112