Leetcode100128. 高访问员工

编程入门 行业动态 更新时间:2024-10-28 06:30:17

Leetcode100128. 高访问<a href=https://www.elefans.com/category/jswz/34/1767683.html style=员工"/>

Leetcode100128. 高访问员工

Every day a Leetcode

题目来源:100128. 高访问员工

解法1:模拟

把名字相同的员工对应的访问时间(转成分钟数)分到同一组中。

对于每一组的访问时间 accessTime,排序后,判断是否有 accessTime[i] - accessTime[i - 2] < 60,如果有,那么把这一组的员工名字加到答案中。

代码:

/** @lc app=leetcode id=100128 lang=cpp** [100128] 高访问员工*/// @lc code=start
class Solution
{
private:static const int MINUTE = 60;public:vector<string> findHighAccessEmployees(vector<vector<string>> &access_times){map<string, vector<int>> employees;for (const vector<string> &access_time : access_times){string name = access_time[0];string time = access_time[1];int accessTime = MINUTE * stoi(time.substr(0, 2)) + stoi(time.substr(2));employees[name].push_back(accessTime);}vector<string> highAccessEmployees;for (auto &[name, accessTime] : employees){sort(accessTime.begin(), accessTime.end());for (int i = 2; i < accessTime.size(); i++)if (accessTime[i] - accessTime[i - 2] < 60){highAccessEmployees.push_back(name);break;}}return highAccessEmployees;}
};
// @lc code=end

结果:

复杂度分析:

时间复杂度:O(Lnlogn),其中 n 为数组 access_times 的长度,L 为员工姓名的最大长度,本题不超过 10。

空间复杂度:O(Ln),其中 n 为数组 access_times 的长度,L 为员工姓名的最大长度,本题不超过 10。

更多推荐

Leetcode100128. 高访问员工

本文发布于:2023-11-15 03:52:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1593188.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:员工

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!