1115. Climbing Stairs

EasyDynamic Programming1D DPFibonacci

You are climbing a staircase with n steps. Each time you may climb either 1 or 2 steps. Return the number of distinct ways to reach the top. The input is JSON {n}.

Input: JSON {n}.

Output: Integer — the number of distinct ways.

Examples

Example 1
Input: {"n":2}
Output: 2
Explanation: 1+1 or 2.
Example 2
Input: {"n":3}
Output: 3
Explanation: 1+1+1, 1+2, or 2+1.
Example 3
Input: {"n":1}
Output: 1
Explanation: One way.

Constraints

Asked by

AccentureAdobeInfosysBloombergAmazonMicrosoft
Solve this problem in the editor →