File tree Expand file tree Collapse file tree 1 file changed +25
-10
lines changed Expand file tree Collapse file tree 1 file changed +25
-10
lines changed Original file line number Diff line number Diff line change 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
5065module . exports = steps ;
You can’t perform that action at this time.
0 commit comments