My Java solution 202 ms


  • 0
    A
    public List<List<Integer>> generate(int numRows) {
            List<List<Integer>> res = new ArrayList<List<Integer>>();
            List<Integer> adding;
            List<Integer> upper = new ArrayList<Integer>();
            int currentRow = 1;
            
            while(currentRow++<=numRows){
                adding = new ArrayList<Integer>(upper);
                adding.add(0,1);
                for(int i=1;i<adding.size()-1;i++){
                    adding.set(i,adding.get(i)+adding.get(i+1));
                }
                res.add(adding);
                upper = new ArrayList<Integer>(adding);
            }
            
            return res;
        }
    

    Any comments?


Log in to reply
 

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