My 2ms solution in java, easily understand


  • 0
    H
    public class Solution {
    public List<Integer> getRow(int rowIndex) {
        List<Integer> ret = new ArrayList<Integer>();
        ret.add(1);
        if (rowIndex == 0){
            return ret;
        }
        else if(rowIndex == 1){
            ret.add(1);
            return ret;
        }
        else{
            ret.add(1);
            int i = 2;
            while(i <= rowIndex){
                int last = 1;
                for(int j = 1; j < ret.size(); j++){
                    int cur = ret.get(j);
                    ret.set(j, last+cur);
                    last = cur;
                }
                ret.add(1);
                
                i++;
            }
            
            return ret;
        }
    }
    

    }


Log in to reply
 

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