My java solution


  • 0
    C
    public class Solution {
    public List<Integer> getRow(int rowIndex) {
       
    List<Integer> prelist = new ArrayList<Integer>();
    //base case
    
    if(rowIndex < 1)
    {
    	prelist.add(1);
    	return prelist;
    }
    
    	prelist.add(1);
    	prelist.add(1);
    	if(rowIndex == 1)
    {
    	return prelist;
    }
    
    else
    {
    	
    	for(int i=2;i<=rowIndex+1;i++)
    	{	List<Integer> laterlist = new ArrayList<Integer>();
    		laterlist.add(0,1);
    		for(int j=1;j<i-1;j++)
    		{	int n1=prelist.get(j-1);int n2=prelist.get(j);
    			laterlist.add(j,n1+n2);
    		}
    		laterlist.add(i-1, 1);
    		
    		prelist = laterlist;
    		
    	}
    	return prelist;
     }
    

    }
    }


Log in to reply
 

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