Skip to content

Commit 6e158ca

Browse files
committed
Trying recursion on steps.
1 parent 09aec22 commit 6e158ca

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

steps/index.js

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* '####'
1515
*/
1616

17-
const steps = (N) => {
17+
const steps = (N, row = 0, stair = '') => {
1818
let i = 0;
1919
let j = 1;
2020
let result = '';
@@ -36,15 +36,30 @@ const steps = (N) => {
3636
// i++;
3737
// }
3838

39-
while(i < N) {
40-
let stair = '';
41-
stair += '#'.repeat(i+1);
42-
stair += ' '.repeat(N-i-1);
43-
stair += '';
44-
result += stair;
45-
i++;
46-
}
47-
return result;
39+
// O(N)
40+
// while(i < N) {
41+
// let stair = '';
42+
// stair += '#'.repeat(i+1);
43+
// stair += ' '.repeat(N-i-1);
44+
// stair += '';
45+
// result += stair;
46+
// i++;
47+
// }
48+
49+
// Try using recursion
50+
// if (N === row) return result;
51+
// if (stair.length === N) {
52+
// result += stair;
53+
// return steps(N, row + 1);
54+
// }
55+
56+
// if (stair.length <= row) {
57+
// stair += '#';
58+
// } else {
59+
// stair += ' ';
60+
// }
61+
62+
// steps(N, row, stair);
4863
}
4964

5065
module.exports = steps;

0 commit comments

Comments
 (0)