题解 | #杨辉三角(二)# | Golang

杨辉三角(二)

https://www.nowcoder.com/practice/486a9408fe2d4912843795c25d43acc2

package main
/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 * 
 * @param num int整型 
 * @return int整型一维数组
*/
func getRow( num int ) []int {
    if num == 0 {
        return []int{1}
    }
    ans := []int{1, 1}
    for i:=2; i <= num; i++ {
        item := make([]int, i+1)
        item[0], item[i] = 1, 1
        for j := 1; j < i; j++ {
            item[j] = ans[j] + ans[j-1]
        }
        ans = item
    }
    return ans
}

全部评论

相关推荐

码农索隆:这种hr,建议全中国推广
点赞 评论 收藏
分享
05-11 20:45
门头沟学院 Java
有担当的灰太狼又在摸...:零帧起手查看图片
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-04 14:35
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务