In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to solve different path problems in leetcode, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
A robot is located in the upper-left corner of a m x n grid (the starting point is marked "Start" in the following figure).
The robot can only move down or to the right one step at a time. The robot attempts to reach the lower right corner of the grid (labeled "Finish" in the following image).
How many different paths are there in total?
For example, the image above is a 7 x 3 grid. How many possible paths are there?
Note: the values of m and n are not more than 100.
Example 1:
Input: M = 3, n = 2
Output: 3
Explanation:
Starting from the upper left corner, there are a total of 3 paths to the lower right corner.
1. Right-> right-> Down
two。 Right-> Down-> right
3. Down-> right-> right
Example 2:
Input: M = 7, n = 3
Output: 28
Ideas for solving the problem:
1. This problem can be broken down into a subproblem, and the final result can be obtained by using the result of the subproblem, a typical dynamic programming.
2 the number of paths = step [imai j] + step [imai 1jjj]
3, iMui 1 is used in jMui 1; so in an incremental way
Code
Func uniquePaths (m int, n int) int {step:=make ([] [] int,m) for ipura
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.