Files
leetcode/top-100-liked/82/leetcode_test.go
T
2026-07-23 16:56:50 +08:00

44 lines
987 B
Go

package top100liked
import (
"testing"
)
// https://leetcode.cn/problems/pascals-triangle/?envType=study-plan-v2&envId=top-100-liked
// 118. 杨辉三角
//
// 给定一个非负整数 `numRows`,生成「杨辉三角」的前 `numRows` 行。
// 在「杨辉三角」中,每个数是它左上方和右上方的数的和。
// 示例 1:
// 输入: numRows = 5
// 输出: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
// 示例 2:
// 输入: numRows = 1
// 输出: [[1]]
//
// 提示:
// - `1 <= numRows <= 30`
//
func generate(numRows int) [][]int {
}
func TestGenerate(t *testing.T) {
cases := []struct {
name string
numRows int
want [][]int
}{
{"example1", 5, [][]int{[]int{1}, []int{1, 1}, []int{1, 2, 1}, []int{1, 3, 3, 1}, []int{1, 4, 6, 4, 1}}},
{"example2", 1, [][]int{[]int{1}}},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
got := generate(c.numRows)
if got != c.want {
t.Errorf("got %v, want %v", got, c.want)
}
})
}
}