Simple Java Solution Easy To Understand


  • 0
    M

    "class Solution {
    public List<Integer> getRow(int rowIndex) {
    ArrayList<Integer> list = new ArrayList<Integer>();
    list.add(1);
    if(rowIndex == 0){
    return list;
    }
    list.add(1);
    if(rowIndex == 1){
    return list;
    }
    for(int i = 2; i <= rowIndex; i++){
    ArrayList<Integer> temp = new ArrayList<Integer>();
    temp.add(1);
    for(int j = 1; j < list.size(); j++){
    temp.add(list.get(j-1) + list.get(j));
    }
    temp.add(1);
    list = temp;
    }
    return list;
    }
    }"


Log in to reply
 

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