일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 괜찮음
- 운동
- leetcode
- 스탭퍼
- 만화도
- 미드시청
- 영어원서읽기
- 프로젝트
- Problem Solving
- 사이드
- 파비최
- 3줄정리
- 10분
- 링피트
- 읽기
- 영어공부
- 화상영어
- realclass
- 잡생각
- English
- 30분
- 쓰릴오브파이트
- Writing
- 개발자
- 리얼 클래스
- 월간
- 매일
- FIT XR
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.06.03 Today's Challenge 본문
https://leetcode.com/problems/time-needed-to-inform-all-employees/
Time Needed to Inform All Employees - LeetCode
Can you solve this real interview question? Time Needed to Inform All Employees - A company has n employees with a unique ID for each employee from 0 to n - 1. The head of the company is the one with headID. Each employee has one direct manager given in th
leetcode.com
딱봐도 DFS인데, 실제 구현을 못함.
오늘부터는 구현에 대한 신경도 써야 함.
외워서라도 풀어봅시다!
class Solution:
def dfs(self, manager, informTime, adjList):
maxTime = 0
for subordinate in adjList[manager]:
maxTime = max(maxTime, self.dfs(subordinate, informTime, adjList))
return maxTime + informTime[manager]
def numOfMinutes(self, n: int, headID: int, manager: List[int], informTime: List[int]) -> int:
adjList = defaultdict(list)
for i in range(n):
if manager[i] != -1:
adjList[manager[i]].append(i)
return self.dfs(headID, informTime, adjList)
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.06.05 Today's Challenge (0) | 2023.06.05 |
---|---|
2023.06.04 Today's Challenge (0) | 2023.06.04 |
2023.06.02 Today's Challenge (0) | 2023.06.02 |
2023.06.01 Today's Challenge (0) | 2023.06.01 |
2023.05.31 Today's Challenge (0) | 2023.05.31 |
Comments