跳到主要内容

2432.处理用时最长的那个任务的员工

链接:2432.处理用时最长的那个任务的员工
难度:Easy
标签:数组
简介:返回处理用时最长的那个任务的员工的 id 。

题解 1 - cpp

  • 编辑时间:2023-05-05
  • 执行用时:56ms
  • 内存消耗:34.8MB
  • 编程语言:cpp
  • 解法介绍:遍历。
class Solution {
public:
int hardestWorker(int n, vector<vector<int>>& logs) {
int prev = 0, resVal = 0, res;
for (auto &log : logs) {
int val = log[1] - prev;
if (val > resVal || val == resVal && log[0] < res) resVal = val, res = log[0];
prev = log[1];
}
return res;
}
};

题解 2 - python

  • 编辑时间:2023-05-05
  • 执行用时:368ms
  • 内存消耗:16.2MB
  • 编程语言:python
  • 解法介绍:同上。
class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
prev = 0
resVal = 0
res = 0
for log in logs:
val = log[1] - prev
if val > resVal or val == resVal and log[0] < res:
resVal = val
res = log[0]
prev = log[1]
return res

题解 3 - rust

  • 编辑时间:2023-05-05
  • 执行用时:8ms
  • 内存消耗:2MB
  • 编程语言:rust
  • 解法介绍:同上。
impl Solution {
pub fn hardest_worker(n: i32, logs: Vec<Vec<i32>>) -> i32 {
let mut prev = 0;
let mut resVal = 0;
let mut res = 0;
for log in logs {
let val = log[1] - prev;
if val > resVal || val == resVal && log[0] < res {
resVal = val;
res = log[0];
}
prev = log[1];
}
res
}
}