健身一年多,我們需要專業有實證的觀念幫助我們進入下一階段,出去玩時看到這本書正是我需要的。
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?
Example 1:
1 | Input: n = 2 |
Example 2:
1 | Input: n = 3 |
62. Unique Paths
A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked ‘Finish’ in the diagram below).
How many possible unique paths are there?
Example 1:
1 | Input: m = 3, n = 7 |
Example 2:
1 | Input: m = 3, n = 2 |
Example 3:
1 | Input: m = 7, n = 3 |
57. Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).
You may assume that the intervals were initially sorted according to their start times.
Example 1:
1 | Input: intervals = [[1,3],[6,9]], newInterval = [2,5] |
Example 2:
1 | Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8] |
Example 3:
1 | Input: intervals = [], newInterval = [5,7] |
Example 4:
1 | Input: intervals = [[1,5]], newInterval = [2,3] |
Example 5:
1 | Input: intervals = [[1,5]], newInterval = [2,7] |
56. Merge Intervals
Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.
Example 1:
1 | Input: intervals = [[1,3],[2,6],[8,10],[15,18]] |
Example 2:
1 | Input: intervals = [[1,4],[4,5]] |