Skip to content

Commit

Permalink
feat: add solutions to lcof problem: No.10 - ||
Browse files Browse the repository at this point in the history
面试题 10- II. 青蛙跳台阶问题
  • Loading branch information
YangFong committed Jan 29, 2022
1 parent d196f0e commit 38098ed
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lcof/面试题10- II. 青蛙跳台阶问题/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,33 @@ func numWays(n int) int {
}
```

### **TypeScript**

```ts
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;
}
```

### **Rust**

```rust
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
}
}
```

### **...**

```
Expand Down
9 changes: 9 additions & 0 deletions lcof/面试题10- II. 青蛙跳台阶问题/Solution.rs
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
}
}
8 changes: 8 additions & 0 deletions lcof/面试题10- II. 青蛙跳台阶问题/Solution.ts
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;
}

0 comments on commit 38098ed

Please sign in to comment.