Skip to content

Commit cb303f5

Browse files
committed
stairCase
1 parent d52f0ba commit cb303f5

File tree

1 file changed

+25
-0
lines changed
  • coding Ninjas/DsaJava/0003AssignmentRecursion

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
public class Solution {
3+
4+
5+
public static int staircase(int n){
6+
7+
/* Your class should be named Solution.
8+
* Don't write main() function.
9+
* Don't read input, it is passed as function argument.
10+
* Return output and don't print it.
11+
* Taking input and printing output is handled automatically.
12+
*/
13+
if (n ==1){
14+
return 1;
15+
}
16+
if (n == 2){
17+
return 2;
18+
}
19+
if (n ==3){
20+
return 4;
21+
}
22+
return staircase(n-1)+staircase(n-2)+staircase(n-3);
23+
}
24+
25+
}

0 commit comments

Comments
 (0)