1ms Java Solution


  • 0
    S
    public class Solution {
        public List<List<Integer>> generate(int numRows) {
            List<List<Integer>> result = new ArrayList<List<Integer>>();
            List<Integer> currentRow;
            List<Integer> lastRow;
            for(int row=0;row<numRows;row++){
                currentRow = new ArrayList<Integer>();
                currentRow.add(1);
                for(int total=0;total<(row-1);total++){
                    lastRow = result.get(row-1);
                    currentRow.add(lastRow.get(total)+lastRow.get(total+1));
                }
                if(row>0){
                    currentRow.add(1);
                }
                result.add(currentRow);
            }
            return result;
        }
    }
    

Log in to reply
 

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