My straightforward java solution


  • 0
    L
    public class Solution {
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> result=new ArrayList<List<Integer>>();
        if(numRows==0) return result;
        if(numRows==1){
          result.add(Arrays.asList(1));
          return result;
        }
        result.add(Arrays.asList(1));
        result.add(Arrays.asList(1,1));
        for(int i=2;i<numRows;i++){
            List<Integer> temp=new ArrayList<Integer>();
            temp.add(1);
            for(int j=0;j<result.get(i-1).size()-1;j++){
                temp.add((Integer)result.get(i-1).get(j)+(Integer)result.get(i-1).get(j+1));
            }
            temp.add(1);
            result.add(temp);
        }
        return result;
    }
    

    }


Log in to reply
 

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