#62

Unique Paths

specialist · 605 · lc medium +29 · verified · 66.6% accepted · 18,279 likes · top 72%

play →

Description

A robot starts at the top-left cell of an m x n grid and can only move right or down toward the bottom-right cell. Given m and n, return the number of distinct paths. The answer will not exceed 2 * 109.

Example 1:

Input: m = 3, n = 7
Output: 28

Example 2:

Input: m = 3, n = 2
Output: 3
Explanation: From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
1. Right -> Down -> Down
2. Down -> Down -> Right
3. Down -> Right -> Down

Code

1
2
3