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";
    }
};
相关推荐
艾莉丝努力练剑18 小时前
【AI大模型接入SDK】LLM会话管理模块设计
网络·c++·人工智能·学习·大模型
萧行之18 小时前
可视化技术复盘:从图形语法看 D3、Vega-Lite、ECharts、Observable Plot
前端·学习·数据可视化
小此方18 小时前
「C++AI大模型接入SDK」(一) API接入与本地两种方式对比、API Key获取、API报文详解与简单API的构建
开发语言·c++·人工智能
v_34836087621 天前
Android native端 堆栈打印
android·算法
residual_fan1 天前
【学术论文】航空发动机故障诊断智能体:基于持续对比强化学习的动态优化方法
人工智能·算法·数据挖掘·数据分析
小弥儿1 天前
GitHub今日热榜 | 2026-09-15:AI 智能体与本地生成工具领跑
学习·开源
susplus1 天前
【初识ARM】ARM相关基础概念
学习·arm
GG-_-Bond1 天前
9.1 kv存储resp协议模拟面试
c++
GreenTea1 天前
OpenAI Agents API 上手实测:一次调用把整个 agent loop 甩给 OpenAI
前端·后端·算法
XiHongShi20161 天前
键盘大小写指示器(代替键盘灯)
学习·计算机