Java dynamic programming


  • 0
    H
        public int climbStairs(int n) {
            if(n==1||n==2){
                return n;
            }
            int[]list=new int[n+1];
            
            list[0]=0;
            list[1]=1;
            list[2]=2;
            for(int i=3;i<n+1;i++){
                list[i]=list[i-1]+list[i-2];
            }
            return list[n];
            
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.