Java Easy Understanding Solution. 1ms


  • 0
    X

    '''
    public class Solution {
    public List<List<Integer>> generate(int numRows) {
    List<List<Integer>> result = new ArrayList<>();
    if (numRows < 1) return result;
    result.add(Arrays.asList(1));
    if (numRows < 2) return result;
    result.add(Arrays.asList(1,1));

        for(int i=2; i<numRows; i++){
            List<Integer> curr = new ArrayList<>();
            curr.add(1);
            List<Integer> old = result.get(i-1);
            for(int j=1; j<old.size(); j++){
                curr.add(old.get(j-1)+old.get(j));
            }
            curr.add(1);
            result.add(curr);
        }
        return result;
    }
    

    }
    '''


Log in to reply
 

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