1. 程式人生 > >leetcode-Pascal's Triangle II

leetcode-Pascal's Triangle II

和Pascal's Triangle I差不多的思想。

public class Solution {
    public List<Integer> getRow(int rowIndex) {
         ArrayList<Integer> results = new ArrayList<Integer>();
		    results.add(1);
		    for (int i = 1; i <= rowIndex; ++i) {
		      int temp = 1;
		      for (int j = 1; j < i; ++j) {
		        int innerTemp = results.get(j);
		        results.set(j, temp + results.get(j));
		        temp = innerTemp;
		      }
		      System.out.println(results);
		      results.add(1);
		    }
		    return results;
    }
}


相關推薦

LeetCode Pascal's Triangle II

Problem Given an index k, return the kth row of the Pascal’s triangle. For example, given k = 3, Return [1,3,3,1]. Note:

[LeetCode] Pascal's Triangle II 楊輝三角之二

Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note that the row index starts from 0. In Pascal's triang

leetcode-Pascal's Triangle II

和Pascal's Triangle I差不多的思想。 public class Solution { public List<Integer> getRow(int rowIndex) { ArrayList<Integer&g

Leetcode 119. Pascal's Triangle II

Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note t

LeetCode】140.Pascal's Triangle II

題目描述(Easy) Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note that the row index starts

LeetCode(Python版)——119. Pascal's Triangle II

Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note that the row index starts from 0. In

LeetCodePascal's Triangle II

原題: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimi

[leetcode]Pascal's triangle 2

Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note that the row index starts from 0. 分析:

LeetCode Pascal's Triangle

Problem Given numRows, generate the first numRows of Pascal’s triangle. For example, given numRows = 5, Return [ [1

119. Pascal's Triangle II(楊輝三角簡單變形)

【題目】 Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note that the row index starts from

Leetcode-Pascal's triangle

楊輝三角: Given numRows, generate the first numRows of Pascal’s triangle. For example, given numRo

Pascal's Triangle II 生成楊輝三角中的某行

題目: 連結 解答: 在上一題基礎上修改,注意行號。 程式碼: class Solution { public: vector<int> getRow(int rowIndex) { vector<vector<int> > res

LeetCode | Pascal's Triangle(楊輝三角)

Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return [ [1], [1,1], [1,2,

Pascal's Triangle II:節省空間楊輝三角

Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [

leetCode-Pascal's Triangle II

triangle pan ace arraylist public clas val solution script Description: Given an index k, return the kth row of the Pascal’s triangle. F

leetcode 119. Pascal's Triangle II

[1] note AD gif anim lee media rip turn Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal‘s triangle. N

leetcode: 119. Pascal's Triangle II

Difficulty Easy. Problem Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note that the row

LeetCode演算法題-Pascal's Triangle II(Java實現)

這是悅樂書的第171次更新,第173篇原創 01 看題和準備 今天介紹的是LeetCode演算法題中Easy級別的第30題(順位題號是119)。給定非負索引k,其中k≤33,返回Pascal三角形的第k個索引行。行索引從0開始。在Pascal的三角形中,每個數字是它上面兩個數字的總和。例如: 輸

leetcode (Pascal's Triangle II)

Title: Merge Stored Array    119 Difficulty:Easy 原題leetcode地址:https://leetcode.com/problems/pascals-triangle-ii/   本題很簡單