Triangle. Surprisingly, this problem can be solved by the same method as in Pascal’s Triangle.

# Month: July 2017

Pascal’s Triangle II. Not sure if there is a better one, I solve this problem using exactly the same solution as I have in Pascal’s Triangle.

Pascal’s Triangle. Just general Pascal’s triangle row by row, based the Math definition.

Populating Next Right Pointers in Each Node II. Same as Populating Next Right Pointers in Each Node. But you need to be more flexible because all the next pointers of a…

Populating Next Right Pointers in Each Node. Low level list node operation. You need to link the left child to the right child of a root first, then link the…

Distinct Subsequences. Classic DP problem. Define dp[i,j] is the number of distinct subsequences between s[0..j-1] and t[0..i-1]. (it is a bit tedious on the subscript) Then if s[j] == t[i]…

Minimum Depth of Binary Tree. Just recursively calculate the min depth of left and right subtree, pick the smaller one and add one to the depth.

Convert Sorted List to Binary Search Tree. Same solution as Convert Sorted Array to Binary Search Tree. But you need to use a trick to get the middle point in the…

Convert Sorted Array to Binary Search Tree. Just take a middle node as the root and construct left and right tree recursively.

Binary Tree Level Order Traversal II. Same solution as Binary Tree Level Order Traversal. I use a stack to reverse the level order.