【拒绝算法PUA】2274. 不含特殊楼层的最大连续楼层数

LeetCode 2274题最大连续楼层数解法

系列文章目录

【拒绝算法PUA】0x00-位运算
【拒绝算法PUA】0x01- 区间比较技巧
【拒绝算法PUA】0x02- 区间合并技巧
【拒绝算法PUA】0x03 - LeetCode 排序类型刷题
【拒绝算法PUA】LeetCode每日一题系列刷题汇总-2025年持续刷新中

C++刷题技巧总结:
[温习C/C++]0x04 刷题基础编码技巧



LeetCode 2274. 不含特殊楼层的最大连续楼层数

链接

2274. 不含特殊楼层的最大连续楼层数

题目

Alice 管理着一家公司,并租用大楼的部分楼层作为办公空间。Alice 决定将一些楼层作为 特殊楼层 ,仅用于放松。

给你两个整数 bottom 和 top ,表示 Alice 租用了从 bottom 到 top(含 bottom 和 top 在内)的所有楼层。另给你一个整数数组 special ,其中 special[i] 表示  Alice 指定用于放松的特殊楼层。

返回不含特殊楼层的 最大 连续楼层数。

 

示例 1:

输入:bottom = 2, top = 9, special = [4,6]
输出:3
解释:下面列出的是不含特殊楼层的连续楼层范围:
- (2, 3) ,楼层数为 2 。
- (5, 5) ,楼层数为 1 。
- (7, 9) ,楼层数为 3 。
因此,返回最大连续楼层数 3 。
示例 2:

输入:bottom = 6, top = 8, special = [7,6,8]
输出:0
解释:每层楼都被规划为特殊楼层,所以返回 0 。
 

提示

1 <= special.length <= 105
1 <= bottom <= special[i] <= top <= 109
special 中的所有值 互不相同

解题方法1

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

class Solution {
public:
    int maxConsecutive(int bottom, int top, vector<int>& special) {
        int ret = 0;
        vector<vector<int>> book;
        vector<int> buildings;
        for (int i = 0; i < top + 1; i++) {
            buildings.push_back(i);
        }
        std::sort(special.begin(), special.end(), std::less<int>());
        int left = bottom;
        for (auto& right : special) {
            vector<int> vec {};
            while (left < right) {
                vec.push_back(buildings[left]);
                left++;
            }
            book.push_back(vec);
            int nn = vec.size();
            ret = max(ret, nn);
            left += 1;
        }
        if (left < top) {
            vector<int> tmpVec;
            tmpVec.insert(tmpVec.end(), buildings.begin() + left, buildings.end());
            book.push_back(tmpVec);
            int nn = tmpVec.size();
            ret = max(ret, nn);
        }
        return ret;
    }
};

int main(int argc, char **argv) {
    Solution obj;
    int bottom = 2;
    int top = 9;
    vector<int>special = {6,4};
    int ret = obj.maxConsecutive(bottom, top, special);
    cout << ret << endl;
    return 0;
}

在这里插入图片描述

输出:

3

解题方法2(代码优化版本)

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

class Solution {
public:
    int maxConsecutive(int bottom, int top, vector<int>& special) {
        int ret = 0;
        std::sort(special.begin(), special.end(), std::less<int>());

        vector<pair<int, int>> book;
        int left = bottom;
        for (int i = 0; i < special.size(); i++) {
            int right = special[i];
            book.push_back({left, right - 1});
            ret = max(ret, right - 1 - left + 1);
            left = right + 1;
        }

        if (left < top) {
            book.push_back({left, top});
            ret = max(ret, top - left + 1);
        }

        return ret;
    }
};

在这里插入图片描述

### 关于 PUA.MPE.BURDEN.A 的病毒类型、定义及特征 PUA.MPE.BURDEN.A 是一种潜在不需要的应用程序(Potentially Unwanted Application, 简称 PUA),通常与恶意软件或广告软件相关联。以下是关于该类型的详细描述: #### 类型 PUA.MPE.BURDEN.A 被分类为 **潜在不必要的应用程序**,这意味着它可能不会直接破坏系统功能,但会对用户体验造成负面影响[^4]。 #### 定义 此类病毒主要通过捆绑安装或其他隐蔽方式进入用户的计算机系统。它们可能会收集用户据、显示侵入性广告或将流量重定向到不可信网站,从而影响设备性能和隐私安全[^5]。 #### 特征 1. **隐秘安装**: 用户往往在不知情的情况下下载并安装这些程序,通常是由于未仔细阅读软件许可协议中的附加组件说明。 2. **资源消耗高**: 运行时占用大量 CPU 和内存资源,可能导致系统变慢甚至崩溃。 3. **弹窗广告频繁**: 显示大量的商业推广信息干扰正常操作体验。 4. **跟踪活动**: 可能记录浏览习惯和其他个人行为用于精准营销目的;某些情况下还涉及更深层次的据窃取行为违反隐私权规定[^6]。 对于防范措施方面建议定期更新防病毒软件据库保持最新状态以便及时检测清除威胁源;同时谨慎对待来自未知发件人的邮件附件链接以及第三方应用商店外的产品下载请求以降低感染几率。 ```python import os from antivirus_api import scan_file def check_virus(file_path): result = scan_file(file_path) if 'PUA.MPE.BURDEN.A' in result['threats']: print(f"The file {file_path} is infected with PUA.MPE.BURDEN.A.") else: print(f"No threat detected in the file {file_path}.") # Example usage check_virus('/path/to/suspicious/file.exe') ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值