일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 개발자
- leetcode
- 프로젝트
- 리얼 클래스
- 화상영어
- 월간
- 운동
- realclass
- 파비최
- 10분
- 영어공부
- 30분
- English
- Problem Solving
- 스탭퍼
- FIT XR
- Daily Challenge
- 만화도
- 읽기
- 링피트
- 매일
- 잡생각
- 뭐든
- Writing
- 3줄정리
- 사이드
- 미드시청
- 괜찮음
- 영어원서읽기
- 쓰릴오브파이트
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/out-of-boundary-paths/
Out of Boundary 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
단순 재귀로 풀 수도 있는데, lru_cache라는 옵션을 추가하면 속도가 엄청나게 향상되는 듯
class Solution:
def findPaths(self, m: int, n: int, maxMove: int, startRow: int, startColumn: int) -> int:
mod = (10**9)+7
@lru_cache(None)
def moves(move, r, c):
if r == m or r < 0 or c < 0 or c == n:
return 1
if move == 0:
return 0
move -= 1
return (moves(move, r+1, c) + moves(move, r, c+1) + moves(move, r-1, c) + moves(move, r, c-1)) % mod
return moves(maxMove, startRow, startColumn)
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
Today's Challenge (0) | 2022.07.18 |
---|---|
Today's Challenge (0) | 2022.07.17 |
Today's Challenge (0) | 2022.07.15 |
Today's Challenge (0) | 2022.07.14 |
Today's Challenge (0) | 2022.07.13 |
Comments