博客
关于我
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服务注册流程
查看>>
Nacos服务部署安装
查看>>
nacos本地可以,上服务器报错
查看>>
Nacos注册Dubbo(2.7.x)以及namespace配置
查看>>
Nacos注册中心有几种调用方式?
查看>>
nacos注册失败,Feign调用失败,feign无法注入成我们的bean对象
查看>>
nacos源码 nacos注册中心1.4.x 源码 nacos源码如何下载 nacos 客户端源码下载地址 nacos discovery下载地址(一)
查看>>
nacos源码 nacos注册中心1.4.x 源码 spring cloud alibaba 的discovery做了什么 nacos客户端是如何启动的(二)
查看>>
nacos源码 nacos注册中心1.4.x 源码 如何注册服务 发送请求,nacos clinet客户端心跳 nacos 注册中心客户端如何发送的心跳 (三)
查看>>