My java solution by using recursion


  • 0
    S
    public class Solution {
    	    public List<Integer> getRow(int rowIndex) {
    	    	
    	    	
    	    	List <Integer> row = new ArrayList<Integer>();
    	    	if(rowIndex<0) return row;
    	    	List <Integer> row1 = getRow(rowIndex-1);
    	        
    	    	for(int i =0;i<rowIndex+1;i++){
    	    			if(i==0||i==rowIndex){
    	    				row.add(1);
    	    			}
    	    			else{
    	    				row.add(row1.get(i-1)+row1.get(i));
    	    			}
    	    			
    	    		}
    	    		
    			return row;
    	        
    	    
    	        
    	    }
    	}

Log in to reply
 

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