[Leetcode] (python): 062 Unique Path

Source: Internet
Author: User

Source of the topic

https://leetcode.com/problems/unique-paths/

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 is there?

Test instructions Analysis

INPUT:M, N

Output:the Number of Unique path

Conditions: Output all possible paths

Topic ideas

A look at the whole arrangement, notice (m=3,n=7), that is to go down 2 steps to the right 6 steps, then the full arrangement can get the path is f (2+6)/(f (2) *f (6)), F is the factorial function

AC Code (PYTHON)

1 __author__='YE'2 3 classsolution (object):4     defuniquepaths (self, M, N):5         """6 : Type M:int7 : Type N:int8 : Rtype:int9         """Ten         defFAC (n): OneF = 1 A              forIinchRange (1, n + 1): -F *=I -             returnF the  -M-= 1 -N-= 1 -         ifm = = 0orn = =0: +             return1 -         returnFAC (m + N)/(FAC (M) *FAC (n)) +  A Print(Solution (). Uniquepaths (3, 7))

[Leetcode] (python): 062 Unique Path

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.