3 ms Java solution


  • 1
    Y
    public List<Integer> getRow(int rowIndex) {
        List<Integer> list = new ArrayList<Integer>();
        list.add(1);
        if(rowIndex==0) return list;
        list.add(1);
        for(int i=2;i<=rowIndex;i++){
            for(int j=1;j<i;j++){
                list.add(j-1,list.get(j)+list.remove(j-1));
            }
            list.add(0,1);
        }
        return list;
    }
    

    Pay attention to the order of get() and remove(). I had made a mistake here.


Log in to reply
 

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