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

栏目: PHP · 发布时间: 7年前

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

2 0 1 9 -5 -29   期三  

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

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

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

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

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

/**
     * @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


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Distributed Algorithms: An Intuitive Approach

Distributed Algorithms: An Intuitive Approach

Wan Fokkink / MIT Press / 2018-2-2 / USD 48.00

The new edition of a guide to distributed algorithms that emphasizes examples and exercises rather than the intricacies of mathematical models. This book offers students and researchers a guide to ......一起来看看 《Distributed Algorithms: An Intuitive Approach》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码