博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[LeetCode]--62. Unique Paths
阅读量:6908 次
发布时间:2019-06-27

本文共 991 字,大约阅读时间需要 3 分钟。

A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).

The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked ‘Finish’ in the diagram below).

How many possible unique paths are there?

这里写图片描述

Above is a 3 x 7 grid. How many possible unique paths are there?

Note: m and n will be at most 100.

想法就是看每个点有多少来源,就会有多少条路径,比如[1][1]点它的来源就是[0][1]和[1][0]两点的来源之和。就大概是这么个意思。很容易理解,最后返回[m-1][n-1]这个点的值就是独立路径条数。

public class Solution {
public int uniquePaths(int m, int n) { if (m == 0 || n == 0) return 0; int[][] sum = new int[m][n]; for (int i = 0; i < m; i++) sum[i][0] = 1; for (int i = 0; i < n; i++) sum[0][i] = 1; for (int i = 1; i < m; i++) { for (int j = 1; j < n; j++) { sum[i][j] = sum[i - 1][j] + sum[i][j - 1]; } } return sum[m - 1][n - 1]; }}

转载地址:http://ehwcl.baihongyu.com/

你可能感兴趣的文章
十月百度,阿里巴巴,迅雷搜狗最新面试七十题(更新至10.17)
查看>>
java程序c:forEach相关实际应用
查看>>
PS命令
查看>>
IP地址规划
查看>>
在ssh项目中导出excel
查看>>
struts-上传
查看>>
javascript的for in
查看>>
MongoDB通过Save修改数据
查看>>
大容量导入和导出数据 -- 介绍
查看>>
我的友情链接
查看>>
第三次作业
查看>>
基于MariaDB-10 半同步复制数据的配置解析
查看>>
关于虚拟机安装linux的发生的网络不通的问题。及解决方案
查看>>
Memcache的简单笔记
查看>>
忘记密码
查看>>
CentOS虚拟机静态IP配置过程及问题分析
查看>>
第一天 css学习
查看>>
linux sort(每日一令之二十二)
查看>>
Cisco Plus 大会资料
查看>>
用thinkphp做的留言板
查看>>