일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 쓰릴오브파이트
- FIT XR
- 미드시청
- 괜찮음
- 사이드
- 뭐든
- 월간
- 3줄정리
- 영어원서읽기
- 링피트
- 10분
- 리얼 클래스
- 만화도
- 화상영어
- Problem Solving
- Daily Challenge
- 개발자
- 읽기
- 매일
- 파비최
- 잡생각
- 영어공부
- 30분
- realclass
- 프로젝트
- 스탭퍼
- Writing
- 운동
- leetcode
- English
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/where-will-the-ball-fall/
Where Will the Ball Fall - 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
딱봐도 DFS/BFS 문제긴 한데..
사선으로 되어 있어서 접근하기가 뭔가 =_=;
class Solution:
def findBall(self, grid: List[List[int]]) -> List[int]:
m, n = len(grid), len(grid[0])
def check(r, c):
if r == m:
return c
nc = c + grid[r][c]
if nc == n or nc == -1 or grid[r][nc] != grid[r][c]:
return -1
else:
return check(r+1, nc)
res = []
for i in range(n):
res.append(check(0, i))
return res
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
Today's Challenge (0) | 2022.11.03 |
---|---|
Today's Challenge (0) | 2022.11.02 |
Today's Challenge (0) | 2022.10.31 |
Today's Challenge (0) | 2022.10.30 |
Today's Challenge (0) | 2022.10.29 |
Comments