zoukankan      html  css  js  c++  java
  • LeetCode & Q119-Pascal's Triangle II-Easy

    Description:

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

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

    my Solution:

    public class Solution {
        public List<Integer> getRow(int rowIndex) {
            List<List<Integer>> list = new ArrayList<List<Integer>>();
            ArrayList<Integer> row = new ArrayList<Integer>();
            for (int i = 0; i <= rowIndex; i++) {
                row.add(0, 1);
                for (int j = 1; j < i; j++) {
                    row.set(j, row.get(j) + row.get(j+1));
                }
            }
            return row;
        }
    }
    
  • 相关阅读:
    hdoj:2075
    hdoj:2072
    hdoj:2071
    hdoj:2070
    hdoj:2069
    test001
    hdoj:2067
    hdoj:2061
    hdoj:2058
    hdoj:2057
  • 原文地址:https://www.cnblogs.com/duyue6002/p/7170627.html
Copyright © 2011-2022 走看看