Leetcode基础刷题之PHP解析(119. Pascal's Triangle II)


2019-5-29 期三 

如果当前没有针对性的话,那就从头把之前补上。

Leetcode基础刷题之PHP解析(118. Pascal's Triangle)


e5d06803f59e0e0cfcefee39b5b3a903.png


这道题和上一道题有一点不同的是返回给定行数的各个值。

图中我们也能知道给定多少行,当前行就有多少个数。把昨天的变动一下,就是今天的需求

    /**
     * @param Integer $rowIndex
     * @return Integer[]
     */
    function getRow($rowIndex) {
        $res[0]=1;
        for($i=1;$i<=$rowIndex;$i++){
            for($j=$i;$j>=0;$j--){
                $res[$j] +=$res[$j-1];
            }
        }
        return $res;
    }

Github整理地址:https://github.com/wuqinqiang/leetcode-php


点赞 取消点赞 收藏 取消收藏

<< 上一篇: Leetcode PHP题解--D74 999. Available Captures for Rook

>> 下一篇: Leetcode PHP题解--D75 706. Design HashMap