일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 잡생각
- 영어원서읽기
- 링피트
- 화상영어
- Daily Challenge
- 개발자
- 리얼 클래스
- realclass
- 스탭퍼
- Writing
- 괜찮음
- 3줄정리
- 쓰릴오브파이트
- leetcode
- 매일
- 만화도
- 미드시청
- 사이드
- English
- 월간
- 30분
- 10분
- Problem Solving
- 운동
- FIT XR
- 프로젝트
- 뭐든
- 읽기
- 영어공부
- 파비최
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.03.26 Today's Challenge 본문
https://leetcode.com/problems/longest-cycle-in-a-graph/
Longest Cycle in a Graph - LeetCode
Can you solve this real interview question? Longest Cycle in a Graph - You are given a directed graph of n nodes numbered from 0 to n - 1, where each node has at most one outgoing edge. The graph is represented with a given 0-indexed array edges of size n,
leetcode.com
가장 긴 사이클 구하는 문제
class Solution:
def longestCycle(self, edges: List[int]) -> int:
lcl = -1
ts = 1
nvat = [0] * len(edges)
for n in range(len(edges)):
if nvat[n] > 0:
continue
st = ts
u = n
while u != -1 and nvat[u] == 0:
nvat[u] = ts
ts += 1
u = edges[u]
if u != -1 and nvat[u] >= st:
lcl = max(lcl, ts-nvat[u])
return lcl
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.03.28 Today's Challenge (0) | 2023.03.28 |
---|---|
2023.03.27 Today's Challenge (0) | 2023.03.27 |
2023.03.25 Today's Challenge (0) | 2023.03.25 |
2023.03.24 Today's Challenge (0) | 2023.03.24 |
2023.03.23 Today's Challenge (0) | 2023.03.23 |
Comments