PART7 队列

最近的请求次数

lc.933

cpp 复制代码
class RecentCounter {
public:
    vector<int> arr;
    RecentCounter() {
        arr.push_back(0);
    }
    
    int ping(int t) {
        arr.push_back(t);
        while (arr[0] < t - 3000) {
            arr.erase(arr.begin());
        }
        return arr.size() - (arr[0] == 0 ? 1 : 0);
    }
};

Dota2 参议院

lc.649

cpp 复制代码
class Solution {
public:
    string predictPartyVictory(string senate) {
        queue<int> R, D;
        for (int i = 0; i < senate.size(); i++) {
            if (senate[i] == 'R') {
                R.push(i);
            } else {
                D.push(i);
            }
        }
        while (!R.empty() && !D.empty()) {
            int r0 = R.front(), d0 = D.front();
            if (r0 < d0) {
                R.push(r0 + senate.size());
            } else {
                D.push(d0 + senate.size());
            }
            R.pop();
            D.pop();
        }
        return D.empty() ? "Radiant" : "Dire";
    }
};
相关推荐
lisw051 小时前
稀疏算法概述!
算法·机器人·无人机
思想觉悟2 小时前
Aosp实战之自定义开机启动进程
c++·面试
YLCHUP3 小时前
【括号匹配+dp优化】题解:双端括号(brackets)_动态规划_状态优化_数学建模_贪心_性质挖掘_STLmap_C++算法竞赛
数据结构·c++·笔记·算法·数学建模·贪心算法·动态规划
郝学胜-神的一滴4 小时前
Effective STL 条款09:慎重选择删除元素的方法
开发语言·网络·数据结构·c++·算法·stl
console.log('npc')6 小时前
Python第9课 类学习笔记,前端js语法对照
前端·python·学习
geovindu8 小时前
python:Logistic Regression
开发语言·后端·python·算法
geovindu9 小时前
python: Random Forest
开发语言·后端·python·算法·随机森林
derek199710 小时前
软考软件设计师:主键、传递依赖和冗余,三问其实是一件事
c语言·c++·计算机网络·软件工程·学习方法
凌冰_10 小时前
数据结构 - 线性结构(三)
java·数据结构·算法·软件工程
拂拉氏10 小时前
【知识讲解】 数据结构与算法-树状数组的认识
数据结构·算法·树状数组