Java Solution


  • 0
    class Solution {
        public List<List<Integer>> generate(int numRows) {
            if(numRows == 0)
                return new LinkedList<>();
            List<List<Integer>> outerlist = new LinkedList<>();
            Integer[] last = {};
            for(int i = 0 ; i < numRows; i++){
                Integer[] arr = new Integer[last.length+1];
                arr[0] = 1;
                arr[arr.length-1] = 1;
                for(int j = 1; j < arr.length-1; j++){
                    arr[j] = last[j-1] + last[j];
                }
                last = arr;
                outerlist.add(Arrays.asList(arr));
            }
            
            return outerlist;
        }
    }
    

Log in to reply
 

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