Skip to content

Commit 9ec47ee

Browse files
authored
feat: add js solution to lcci problem: No.08.01.Three Steps Problem (doocs#393)
1 parent 30d7e1e commit 9ec47ee

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

lcci/08.01.Three Steps Problem/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@ class Solution {
7373
}
7474
```
7575

76+
### **JavaScript**
77+
78+
```js
79+
/**
80+
* @param {number} n
81+
* @return {number}
82+
*/
83+
var waysToStep = function(n) {
84+
if (n < 3) return n;
85+
let a = 1, b = 2, c = 4;
86+
for (let i = 3; i < n; i++) {
87+
[a, b, c] = [b, c, (a + b + c) % 1000000007];
88+
}
89+
return c;
90+
};
91+
```
92+
7693
### **C++**
7794

7895
```cpp

lcci/08.01.Three Steps Problem/README_EN.md

+17
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,23 @@ class Solution {
6767
}
6868
```
6969

70+
### **JavaScript**
71+
72+
```js
73+
/**
74+
* @param {number} n
75+
* @return {number}
76+
*/
77+
var waysToStep = function(n) {
78+
if (n < 3) return n;
79+
let a = 1, b = 2, c = 4;
80+
for (let i = 3; i < n; i++) {
81+
[a, b, c] = [b, c, (a + b + c) % 1000000007];
82+
}
83+
return c;
84+
};
85+
```
86+
7087
### **C++**
7188

7289
```cpp
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @param {number} n
3+
* @return {number}
4+
*/
5+
var waysToStep = function(n) {
6+
if (n < 3) return n;
7+
let a = 1, b = 2, c = 4;
8+
for (let i = 3; i < n; i++) {
9+
[a, b, c] = [b, c, (a + b + c) % 1000000007];
10+
}
11+
return c;
12+
};

0 commit comments

Comments
 (0)