Java-DS-Algo

Run Settings
LanguageJava
Language Version
Run Command
class Main { public static void main(String[] args) { CountStairSteps cs = new CountStairSteps(); int stepsCount = CountStairSteps.countStairUpSteps(3); System.out.println("stepsCount: "+stepsCount); } }
import java.util.*; class CountStairSteps{ public static void main(String arg[]){ int n =5; int stepsCount = countStairUpSteps(n); System.out.println("stepsCount: "+stepsCount); } static ArrayList<Integer> al = new ArrayList<>(); public static int countStairUpSteps(int n){ //initizing arraylist for(int i=0;i<=5;i++){ al.add(0); } if(n<0){ return -1; } if(n==0 || n==1){ return 1; } if(al.get(n)!=0) return al.get(n); int sum =countStairUpSteps(n-1)+countStairUpSteps(n-2); al.set(n,sum); return sum; } }
Editor Settings
Theme
Key bindings
Full width
Lines