70. Climbing Stairs
问题
You are climbing a staircase. It takes n steps to reach the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
递归,传入根节点,进行BFS搜索。
如果当前节点小于搜索的最低点,则抛弃该节点,继续搜索其右子节点。(由于是BST,右子节点大于节点本身)
如果当前节点大于搜索的最高点,则抛弃该节点,继续搜索其左子节点。
如果当前节点在搜索范围内,则保留该节点,继续递归该节点的两个子节点。
最后返回根节点。
1 | /** |
70. Climbing Stairs