• LeetCode——Pascal's Triangle II


    Description:

    Given an index k, return the kth row of the Pascal's triangle.

    For example, given k = 3, Return [1,3,3,1].

    public class Solution {
        public List<Integer> getRow(int rowIndex) {
            List<List<Integer>> list = new ArrayList<List<Integer>>();
            for(int i=0; i<=rowIndex; i++) {
                List<Integer> tList = new ArrayList<Integer>();
                if(i == 0) {
                    tList.add(1);
                }
                else {
                    for(int j=0; j<=i; j++) {
                        if(j == 0 || j == i) {
                        tList.add(1);
                    }
                    else {
                        tList.add(list.get(i-1).get(j) + list.get(i-1).get(j-1));
                    }
                    }
                }
                list.add(tList);
            }
            return list.get(rowIndex);
            
        }
    }
    
  • 相关阅读:
    case when if
    存储过程 、函数和事务
    poj 2263
    hdu -1874
    poj 2472
    2544 hdu
    模板floyed
    模板Dijkstra
    hdu 2066
    hdu 2544
  • 原文地址:https://www.cnblogs.com/wxisme/p/4589816.html
Copyright © 2020-2023  润新知