파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 8. 1. 23:45

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

 

Unique Paths - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

DP를 이용한 간단한 풀이 문제.
나에겐 그닥 간단친 않음 ㅠㅠ

class Solution:
    def uniquePaths(self, m: int, n: int) -> int:
        def solve(y, x):
            if y == m-1 or x == n-1:
                return 1
            if dp[y][x] != 0:
                return dp[y][x]
            
            dp[y][x] = solve(y+1, x) + solve(y, x+1)
            return dp[y][x]
        
        dp = [[0 for x in range(n)] for y in range(m)]
        return solve(0,0)
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2022.08.03
Today's Challenge  (0) 2022.08.02
Today's Challenge  (0) 2022.07.31
Today's Challenge  (0) 2022.07.30
Today's Challenge  (0) 2022.07.29
Comments