博客
关于我
LeetCode119.杨辉三角2Golang版
阅读量:382 次
发布时间:2019-03-05

本文共 410 字,大约阅读时间需要 1 分钟。

LeetCode119.杨辉三角2Golang版

1. 题目描述

给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行。

在杨辉三角中,每个数是它左上方和右上方的数的和。

输入: 3

输出: [1,3,3,1]

2. 思路分析

按照列来遍历的时候,需要从后往前遍历才不会导致数据的覆盖

3. 代码

func getRow(rowIndex int) []int {       yanghui := make([]int,rowIndex + 1)        yanghui[0] = 1    for i := 1; i <= rowIndex; i++ {           for j := i; j > 0; j-- {               yanghui[j] = yanghui[j-1] + yanghui[j]        }    }    return yanghui}

转载地址:http://nlcwz.baihongyu.com/

你可能感兴趣的文章
nacos集群网络分区对的影响和运维方式
查看>>
nacos集群节点故障对应用的影响以及应急方法
查看>>
nacos集群配置详解
查看>>
Nagios 3.0 Jumpstart Guide For Linux – Overview, Installation and Configuration
查看>>
nagios 实时监控 iptables 状态
查看>>
WAP短信格式解析及在Linux下用C语言实现
查看>>
nagios+cacti整合
查看>>
Nagios介绍
查看>>
nagios利用NSCient监控远程window主机
查看>>
nagios安装文档
查看>>
nagios服务端安装
查看>>
Nagios自定义监控脚本
查看>>
name_save matlab
查看>>
Nami 项目使用教程
查看>>
Nancy之基于Nancy.Hosting.Aspnet的小Demo
查看>>
NAND NOR FLASH闪存产品概述
查看>>
nano 编辑
查看>>
nanoGPT 教程:从零开始训练语言模型
查看>>
NASA网站曝严重漏洞,或将沦为黑客钓鱼网站?
查看>>
Nash:轻量级、安全且可靠的脚本语言
查看>>