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";
    }
};
相关推荐
尊治2 小时前
变频器学习入门教程
学习·esim电工仿真·电工仿真软件·电工仿真·电工接线学习·esim电工制图
血色橄榄枝2 小时前
基于用户注册信息的关键词检测挑战赛「Datawhale AI 夏令营」
人工智能·算法·机器学习
tyqtyq222 小时前
旅行打包清单 App — HarmonyOS AI 应用开发技术博客
人工智能·学习·华为·生活·harmonyos
Cx330❀3 小时前
【MySQL基础】一文吃透“表的约束”:从 Null/Default 到主外键的终极安全法则
linux·服务器·数据库·c++·mysql·安全
c238563 小时前
第二篇:《测试指挥官:可视化单题自测框架(含 assert 实操)》
java·数据库·c++·算法·安全性测试
辞旧 lekkk3 小时前
【Redis初阶】常见数据类型
开发语言·数据库·c++·redis·学习·缓存·bootstrap
六点_dn4 小时前
Linux学习笔记-printf命令
linux·运维·算法
遥感知识服务5 小时前
Sentinel-1 + DEM + FwDET + 随机森林:从快速水深初估到多因子误差修正
算法·随机森林·sentinel
小弥儿5 小时前
GitHub今日热榜 | 2026-07-17:教育Agent与极低量化分庭抗礼
学习·开源·github
来一碗刘肉面5 小时前
顺序表与链表的比较
数据结构·算法·链表