| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 스탭퍼
- 프로젝트
- English
- 읽기
- realclass
- 사이드
- 영어공부
- 3줄정리
- 운동
- 10분
- FIT XR
- 화상영어
- Problem Solving
- 영어원서읽기
- 괜찮음
- Daily Challenge
- 링피트
- 매일
- 뭐든
- 리얼 클래스
- Writing
- 잡생각
- 월간
- 쓰릴오브파이트
- 30분
- 미드시청
- 만화도
- leetcode
- 파비최
- 개발자
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