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

60 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package top100liked
import (
"testing"
)
// https://leetcode.cn/problems/unique-paths/?envType=study-plan-v2&envId=top-100-liked
// 62. 不同路径
//
// 一个机器人位于一个 `m x n` 网格的左上角 (起始点在下图中标记为 “Start” )。
// 机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为 “Finish” )。
// 问总共有多少条不同的路径?
// 示例 1
// 输入:m = 3, n = 7
// 输出:28
// 示例 2
// 输入:m = 3, n = 2
// 输出:3
// 解释:
// 从左上角开始,总共有 3 条路径可以到达右下角。
// 1. 向右 -> 向下 -> 向下
// 2. 向下 -> 向下 -> 向右
// 3. 向下 -> 向右 -> 向下
// 示例 3
// 输入:m = 7, n = 3
// 输出:28
// 示例 4
// 输入:m = 3, n = 3
// 输出:6
//
// 提示:
// - `1 <= m, n <= 100`
// - 题目数据保证答案小于等于 `2 * 10^9`
//
func uniquePaths(m int, n int) int {
}
func TestUniquePaths(t *testing.T) {
cases := []struct {
name string
m int
n int
want int
}{
{"example1", 3, 7, 28},
{"example2", 3, 2, 3},
{"example3", 7, 3, 28},
{"example4", 3, 3, 6},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
got := uniquePaths(c.m, c.n)
if got != c.want {
t.Errorf("got %v, want %v", got, c.want)
}
})
}
}