Class Solution
-
- All Implemented Interfaces:
public final class Solution3154 - Find Number of Ways to Reach the K-th Stair.
Hard
You are given a non-negative integer
k. There exists a staircase with an infinite number of stairs, with the lowest stair numbered 0.Alice has an integer
jump, with an initial value of 0. She starts on stair 1 and wants to reach stairkusing any number of operations. If she is on stairi, in one operation she can:Go down to stair
i - 1. This operation cannot be used consecutively or on stair 0.Go up to stair <code>i + 2<sup>jump</sup></code>. And then,
jumpbecomesjump + 1.
Return the total number of ways Alice can reach stair
k.Note that it is possible that Alice reaches the stair
k, and performs some operations to reach the stairkagain.Example 1:
Input: k = 0
Output: 2
Explanation:
The 2 possible ways of reaching stair 0 are:
Alice starts at stair 1.
Alice starts at stair 1.
Example 2:
Input: k = 1
Output: 4
Explanation:
The 4 possible ways of reaching stair 1 are:
Alice starts at stair 1. Alice is at stair 1.
Alice starts at stair 1.
Alice starts at stair 1.
Alice starts at stair 1.
Constraints:
<code>0 <= k <= 10<sup>9</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegerwaysToReachStair(Integer k)-
-
Method Detail
-
waysToReachStair
final Integer waysToReachStair(Integer k)
-
-
-
-