1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
func uniquePaths(m int, n int) int {
	f := make([]int, m*n)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if i == 0 || j == 0 {
				f[i*m+j] = 1
			} else if i-1 < 0 {
				f[i*m+j] = f[i*m+j-1]
			} else if j-1 < 0 {
				f[i*m+j] = f[(i-1)*m+j]
			} else {
				f[i*m+j] = f[(i-1)*m+j] + f[i*m+j-1]
			}
		}
	}
	return f[m*n-1]
}