Skip to content

Commit 93f0461

Browse files
authored
Update Staircase
1 parent 418c2e2 commit 93f0461

File tree

1 file changed

+24
-0
lines changed
  • Course 2 - Data Structures in JAVA/Recursion Assignment

1 file changed

+24
-0
lines changed

Course 2 - Data Structures in JAVA/Recursion Assignment/Staircase

+24
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,27 @@ Sample Input 2 :
2121
Sample Output 2 :
2222
13
2323
*/
24+
25+
public class Solution {
26+
27+
28+
public static int staircase(int n){
29+
30+
/* Your class should be named Solution.
31+
* Don't write main() function.
32+
* Don't read input, it is passed as function argument.
33+
* Return output and don't print it.
34+
* Taking input and printing output is handled automatically.
35+
*/
36+
if (n<0)
37+
{
38+
return 0;
39+
}
40+
else if (n==0)
41+
{
42+
return 1;
43+
}
44+
return staircase(n-1)+staircase(n-2)+staircase(n-3);
45+
}
46+
47+
}

0 commit comments

Comments
 (0)