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

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

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

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


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

查看所有标签

猜你喜欢:

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

The Practice of Programming

The Practice of Programming

Brian W. Kernighan、Rob Pike / Addison-Wesley / 1999-2-14 / USD 49.99

With the same insight and authority that made their book The Unix Programming Environment a classic, Brian Kernighan and Rob Pike have written The Practice of Programming to help make individual progr......一起来看看 《The Practice of Programming》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具