Classes in the new ES6 standard

Class is a new feature introduced into the new ECMAScript 2015 standard, also known as ES6. I thought it was just a move for the JavaScript to adapt to the Object-oriented world. It may be so, howeve

Create a 2-dimensional Array in JavaScript

When I tried to create a two-dimensional array today, I surprisingly discovered that there is no built-in function which can help us to create two-dimensional array in JavaScript. I searched online an

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;

Corner cases for binary trees

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

DFS in Binary Tree

Let’s think about this problem: Sum Root to Leaf Numbers. A general solution is like below:123456789101112131415161718192021222324252627282930313233public int sumNumbers(TreeNode root) { if (

Breadth-First Traversal with Queue

Breadth-First Traversal can be used in many places, such as traversing level-by-level in a binary tree, or BFS in a graph. All those are implemented with a Queue.Binary Tree Level Order TraversalBinar

Array partition with two pointers

Some problem are using this template with minor alternation, such as:Quick SortPartition ArraySort Letters by CaseSort Colors 1234567891011121314151617181920212223242526272829303132333435public int pa