java recurive resolution


  • 0
    P

    public class Solution {
    List<List<Integer>> list = new ArrayList<List<Integer>>();
    public List<List<Integer>> generate(int numRows) {
    List<Integer> temp = new ArrayList<Integer>();
    if(numRows == 0)
    {
    return list;
    }
    if(numRows == 1)
    {
    temp.add(1);
    list.add(temp);
    return list;
    }
    temp.add(1);
    int prelength = numRows - 1;
    List<Integer> prelist = generate(numRows-1).get(numRows-2);
    for(int i = 0;i<prelength-1;i++)
    {
    temp.add(prelist.get(i)+prelist.get(i+1));
    }
    temp.add(1);
    list.add(temp);
    return list;
    }

    }


Log in to reply
 

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