1ms solution using Java


  • 1
    J

    public class Solution {
    public List<List<Integer>> generate(int numRows) {
    List<List<Integer>> res = new ArrayList<List<Integer>>(numRows);

        ArrayList<Integer> row = new ArrayList<Integer>(numRows);
        Integer[] arr = new Integer[numRows];
        for (int i=0; i<numRows; i++) {
            for(int j=i-1; j>=1 ; j--){
                arr[j] = arr[j] + arr[j-1];
            }
            arr[i] = 1;
            res.add(Arrays.asList(Arrays.copyOf(arr, i+1)));
        }
        return res;
    }
    

    }


Log in to reply
 

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