# Tag: DFS

Word Break II. If you purely use back tracking, you will run out of time. The trick is to cache the results so that we don’t have to try break…

Sum Root to Leaf Numbers. Just traverse the tree using DFS, when ever you see a full path (a node that has no child tree node), Add the number of…

Flatten Binary Tree to Linked List. Using DFS, flatten the left tree first, then flatten the right tree, then append the left tree to the root, append the right tree…

Path Sum II. Same method as Path Sum. But this time we need to use a stack to save down the path.

Path Sum. Solved by using DFS. If the root tree has a Path Sum X, then either of the subtree will has a Path Sum X – root.val.

Word Search. This problem looks like a very classic DFS problem for me. I didn’t use any trick to solve it, just use every position in the board as a…

N-Queens II. A Simplified version of N-Queens. No need to output the solution set.