LeetCode75| 队列

目录

933 最近的请求次数

649 Dota2 参议院


933 最近的请求次数

class RecentCounter {
public:
    queue<int>st;
    RecentCounter() {

    }
    
    int ping(int t) {
        st.push(t);
        while(t - st.front() > 3000)st.pop();
        return st.size();
    }
};

时间复杂度O(1)

空间复杂度O(n)//n为队列的最大元素个数

649 Dota2 参议院

class Solution {
public:
    string predictPartyVictory(string senate) {
        int n = senate.size();
        queue<int>R,D;
        for(int i = 0;i < n;i++){
            char ch = senate[i];
            if(ch == 'R'){
                R.push(i);
            }else{
                D.push(i);
            }
        }
        while(!R.empty() && !D.empty()){
            if(R.front() < D.front()){
                R.push(R.front() + n);
            }else{
                D.push(D.front() + n);
            }
            D.pop();
            R.pop();
        }
        if(R.empty())return "Dire";
        return "Radiant"; 
    }
};

 时间复杂度O(n)

空间复杂度O(n)

相关推荐

  1. LeetCode75| 队列

    2023-12-29 08:28:02       58 阅读
  2. LeetCode 75| 前缀和

    2023-12-29 08:28:02       57 阅读
  3. LeetCode 75| 位运算

    2023-12-29 08:28:02       57 阅读
  4. LeetCode75| 单调栈

    2023-12-29 08:28:02       68 阅读
  5. LeetCode 75 颜色分类

    2023-12-29 08:28:02       39 阅读
  6. Leetcode 75. 颜色分类

    2023-12-29 08:28:02       44 阅读
  7. 力扣LeetCode75

    2023-12-29 08:28:02       82 阅读
  8. LeetCode //C - 75. Sort Colors

    2023-12-29 08:28:02       42 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-29 08:28:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-29 08:28:02       106 阅读
  3. 在Django里面运行非项目文件

    2023-12-29 08:28:02       87 阅读
  4. Python语言-面向对象

    2023-12-29 08:28:02       96 阅读

热门阅读

  1. 编程笔记 html5&css&js 011 HTML页面划分

    2023-12-29 08:28:02       48 阅读
  2. 策略模式(及案例)

    2023-12-29 08:28:02       52 阅读
  3. SQL 解析 — 如何轻松实现新增语句

    2023-12-29 08:28:02       45 阅读
  4. 热迁移

    2023-12-29 08:28:02       56 阅读
  5. 开源大语言模型简记

    2023-12-29 08:28:02       53 阅读
  6. 简单工厂设计模式(计算器实例优化)

    2023-12-29 08:28:02       62 阅读
  7. 数据清洗与融合期末考试(常见理论题)

    2023-12-29 08:28:02       58 阅读