My java solution


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

Log in to reply
 

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