zoukankan      html  css  js  c++  java
  • 119. Pascal's Triangle II(js)

    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 Pascal's triangle, each number is the sum of the two numbers directly above it.

    Example:

    Input: 3
    Output: [1,3,3,1]
    题意:二维数组表示的杨辉三角,求出给定行的数据
    代码如下:
    /**
     * @param {number} rowIndex
     * @return {number[]}
     */
    var getRow = function(rowIndex) {
            
               let res=[];
               let temp=2;        
            for(let i=0;i<=rowIndex;i++){
                res[i]=[]
                if(i>0) res[i].push(1)
                for(let j=1;j<i;j++){
                    res[i].push(res[i-1][j]+res[i-1][j-1]);                
                }
                res[i].push(1);
            }         
            return res.pop();
    };
  • 相关阅读:
    SPOJ NDIV
    SPOJ ETF
    SPOJ DIVSUM
    头文件--持续更新
    SPOJ FRQPRIME
    SPOJ FUNPROB
    SPOJ HAMSTER1
    观光
    最短路计数
    拯救大兵瑞恩
  • 原文地址:https://www.cnblogs.com/xingguozhiming/p/10828489.html
Copyright © 2011-2022 走看看