forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add solutions to lcof problem: No.10 - ||
面试题 10- II. 青蛙跳台阶问题
- Loading branch information
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
impl Solution { | ||
pub fn num_ways(n: i32) -> i32 { | ||
let mut tup = (0, 1); | ||
for _ in 0..n { | ||
tup = (tup.1, (tup.0 + tup.1) % 1000000007); | ||
} | ||
tup.1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function numWays(n: number): number { | ||
let a = 0; | ||
let b = 1; | ||
for (let i = 0; i < n; i++) { | ||
[a, b] = [b, (a + b) % 1000000007]; | ||
} | ||
return b; | ||
} |