What the time complexity of this solution?


  • 0
    F
    public class Solution {
    List<List<Integer>> res = new ArrayList<List<Integer>>();
    public List<List<Integer>> generate(int numRows) {
        if(numRows==0) {
            return res;
        }
        getRow(numRows);
        res.add(0,new ArrayList<Integer>(Arrays.asList(1)));
        return res;
    }
    public List<Integer> getRow(int rowIndex) {
        if(rowIndex==1) {
            return new ArrayList<Integer>(Arrays.asList(1));
        }
        if(rowIndex==2) {
            List<Integer> tmp = new ArrayList<Integer>(Arrays.asList(1,1));
            res.add(tmp);
            return tmp;
        }
        List<Integer> list = getRow(rowIndex-1);
        List<Integer> tmp = new ArrayList<Integer>();
        tmp.add(1);
        for(int i=1; i<list.size(); i++) {
            tmp.add(list.get(i)+list.get(i-1));
        }
        tmp.add(1);
        res.add(tmp);
        return tmp;
    }
    

    }


Log in to reply
 

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