Leetcode100128. 高访问员工

Every day a Leetcode

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

解法1:模拟

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

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

代码:

c 复制代码
/*
 * @lc app=leetcode.cn 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。

相关推荐
phltxy3 小时前
C语言操作符详解
java·c语言·算法
RuoZoe3 小时前
从 2026 年 3 月 1 日开源,到 26.10.9:Jalium UI 半年时间到底走了多远?
c语言·c++
aqiu1111114 小时前
【LeetCode 902】最大为 N 的数字组合 - 详细题解与数位组合思路
数据结构·算法·leetcode·蓝桥杯·数位dp
辰烨chenye4 小时前
LeetCode Hot 100 题解 · 哈希篇
算法·leetcode·哈希算法
罗西的思考5 小时前
DreamZero 与 DreamDojo:世界模型与策略的分层协同综合分析与对比
人工智能·算法·机器学习
鱼子星_5 小时前
【C++】继承和多态(上)
c++·笔记
玖玥拾5 小时前
LeetCode 219 存在重复元素 II
算法·leetcode·哈希算法·散列表
知无不研6 小时前
c语言中循环的介绍与简单应用
c语言·开发语言·算法·循环·for·while
郝学胜-神的一滴6 小时前
Qt 高级编程 045:坐标体系深度实战
开发语言·c++·windows·python·qt·程序人生