My Simple and Concise Java Solution


  • -1
    public class Solution {
    public List<List<Integer>> generate(int numRows) {
        ArrayList <List<Integer>> result = new ArrayList<List<Integer>>();
        if (numRows <= 0) return result;
        
        for (int i = 0; i < numRows; i++) {
            ArrayList<Integer> list = new ArrayList<Integer>();
            list.add(1);
            for (int j = 1; j < i; j++) { // From the second element to the last second element
                list.add(result.get(i-1).get(j-1) + result.get(i-1).get(j));
            }
            if (i != 0) list.add(1);
            result.add(new ArrayList<Integer>(list));
        }
        return result;
    }
    

    }


Log in to reply
 

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