Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- python 릿코드
- 파이썬알고리즘
- leetcode풀이
- 파이썬릿코드
- 알고리즘풀이
- 릿코드 파이썬
- 파이썬릿코드풀기
- 상가수익률계산기
- 릿코드
- python xor
- 파이썬알고리즘풀기
- 릿코드 풀기
- 파이썬 알고리즘
- 코틀린기초
- python Leetcode
- 알고리즘풀기
- leetcode풀기
- python 알고리즘
- leetcode 풀기
- python priority queue
- 파이썬 프로그래머스
- python sorted
- binary search
- 파이썬 알고리즘 풀기
- LeetCode
- 파이썬 릿코드
- 릿코드풀이
- python zip_longest
- 릿코드풀기
- 잇츠디모
Archives
- Today
- Total
소프트웨어에 대한 모든 것
2432. The Employee That Worked on the Longest Task 본문
반응형
문제)
2432. The Employee That Worked on the Longest Task
There are n employees, each with a unique id from 0 to n - 1.
You are given a 2D integer array logs where logs[i] = [idi, leaveTimei] where:
- idi is the id of the employee that worked on the ith task, and
- leaveTimei is the time at which the employee finished the ith task. All the values leaveTimei are unique.
Note that the ith task starts the moment right after the (i - 1)th task ends, and the 0th task starts at time 0.
Return the id of the employee that worked the task with the longest time. If there is a tie between two or more employees, return the smallest id among them.
Example 1:
Input: n = 10, logs = [[0,3],[2,5],[0,9],[1,15]]
Output: 1
Explanation:
Task 0 started at 0 and ended at 3 with 3 units of times.
Task 1 started at 3 and ended at 5 with 2 units of times.
Task 2 started at 5 and ended at 9 with 4 units of times.
Task 3 started at 9 and ended at 15 with 6 units of times.
The task with the longest time is task 3 and the employee with id 1 is the one that worked on it, so we return 1.
Example 2:
Input: n = 26, logs = [[1,1],[3,7],[2,12],[7,17]]
Output: 3
Explanation:
Task 0 started at 0 and ended at 1 with 1 unit of times.
Task 1 started at 1 and ended at 7 with 6 units of times.
Task 2 started at 7 and ended at 12 with 5 units of times.
Task 3 started at 12 and ended at 17 with 5 units of times.
The tasks with the longest time is task 1. The employees that worked on it is 3, so we return 3.
Example 3:
Input: n = 2, logs = [[0,10],[1,20]]
Output: 0
Explanation:
Task 0 started at 0 and ended at 10 with 10 units of times.
Task 1 started at 10 and ended at 20 with 10 units of times.
The tasks with the longest time are tasks 0 and 1. The employees that worked on them are 0 and 1, so we return the smallest id 0.
Constraints:
- 2 <= n <= 500
- 1 <= logs.length <= 500
- logs[i].length == 2
- 0 <= idi <= n - 1
- 1 <= leaveTimei <= 500
- idi != idi+1
- leaveTimei are sorted in a strictly increasing order.
솔루션1)
class Solution:
def hardestWorker(self, n: int, logs):
prev_end_time = 0
longest_task_time = 0
longest_task_id = 501
for id, end_time in logs:
worked_time = end_time - prev_end_time
prev_end_time = end_time
if longest_task_time < worked_time:
longest_task_time = worked_time
longest_task_id = id
elif longest_task_time == worked_time:
longest_task_time = worked_time
longest_task_id = min(id, longest_task_id)
return longest_task_id
반응형
'알고리즘 > LeetCode' 카테고리의 다른 글
1704. Determine if String Halves Are Alike (0) | 2022.12.14 |
---|---|
931. Minimum Falling Path Sum (0) | 2022.12.13 |
1026. Maximum Difference Between Node and Ancestor (0) | 2022.12.09 |
6. Zigzag Conversion (0) | 2022.12.07 |
462. Minimum Moves to Equal Array Elements II (0) | 2022.07.01 |
Comments