Leetcode算法题1601-1700


1601-1610

1604.警告一小时内使用相同员工工卡大于等于3次的人

class Solution {
public:
    vector <string> alertNames(vector <string> &keyName, vector <string> &keyTime) {
        unordered_map <string, vector<int>> map;
        int n = keyName.size();
        for (int i = 0; i < n; ++i) {
            int hour = (keyTime[i][0] - '0') * 10 + (keyTime[i][1] - '0');
            int minute = (keyTime[i][3] - '0') * 10 + (keyTime[i][4] - '0');
            map[keyName[i]].emplace_back(hour * 60 + minute);
        }
        vector <string> res;
        for (auto &[name, times]: map) {
            sort(times.begin(), times.end());
            int size = times.size();
            for (int i = 2; i < size; ++i) {
                if (times[i] - times[i - 2] <= 60) {
                    res.emplace_back(name);
                    break;
                }
            }
        }
        sort(res.begin(), res.end());
        return res;
    }
};

1611-1620

1621-1630

1631-1640

1641-1650

1651-1660

1661-1670

1669. 合并两个链表

class Solution {
public:
    ListNode *mergeInBetween(ListNode *list1, int a, int b, ListNode *list2) {
        auto point1 = list1, point2 = list2;
        for (int i = 1; i < a; ++i) point1 = point1->next;
        auto dummy = point1->next;
        point1->next = list2;
        for (int i = 0; i <= b - a; ++i) dummy = dummy->next;
        while (point2->next) point2 = point2->next;
        point2->next = dummy;
        return list1;
    }
};

1671-1680

1681-1690

1691-1700


文章作者: 不二
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 不二 !
  目录