leetcode 3606

3606: 优惠券校验器

复制代码
isalnum(ch)

ch 满足('A'<=ch<='Z') || ('a'<=ch<='z') || ('0'<=ch<='9')时返回真,否则返回假

复制代码
for(auto& group:groups){
    sort(group.begin(),group.end()); //每组内部排序
    ans.insert(ans.end(),group.begin(),group.end());
}
  • insert 的这段调用相当于"把当前组的所有元素整体尾插到 ans 后面"。

  • 4 组依次处理,最终 ans 里就是:electronics 的排序结果 → grocery 的排序结果 → pharmacy 的排序结果 → restaurant 的排序结果。

    class Solution {
    public:
    bool check(string code,bool isActive){
    for(char ch:code){
    if(ch!='_' && !isalnum(ch)) return false;
    }
    return isActive;
    }
    vector validateCoupons(vector& code, vector& businessLine, vector& isActive) {
    vector groups[4]; //长度为 4 的数组
    vector ans;
    for(int i=0;i<code.size();i++){
    if(!code[i].empty() && check(code[i],isActive[i])){
    if(businessLine[i]=="electronics") groups[0].push_back(code[i]);
    else if(businessLine[i]=="grocery") groups[1].push_back(code[i]);
    else if(businessLine[i]=="pharmacy") groups[2].push_back(code[i]);
    else if(businessLine[i]=="restaurant") groups[3].push_back(code[i]);
    }
    }
    for(auto& group:groups){
    sort(group.begin(),group.end()); //每组内部按标识符字典序排序
    ans.insert(ans.end(),group.begin(),group.end());
    }

    复制代码
          return ans;
      }

    };

相关推荐
地平线开发者14 小时前
【模型轻量化专题】衡量模型轻量性的指标
算法
学习星球17 小时前
OFDM技术精讲:正交性推导、循环前缀原理与80行Python链路仿真(附实测数据)
算法·面试·前端框架
alphaTao1 天前
LeetCode 每日一题 2026/8/24-2026/8/30
python·算法·leetcode
Interview Aid1121 天前
TikTok OA 四题分享|半小时内 AC,题目基本都是实现题
java·开发语言·算法·面试·职场和发展
顶点多余1 天前
那些在算法中适合巩固的知识点---1
java·前端·算法
AI情绪识别开源1 天前
检信 ALLEMOTION OS 加密打包可执行程序 — 全面测试报告版本: v1.3功能测试 / 性能测试 /
开发语言·数据结构·人工智能·功能测试
罗西的思考1 天前
【Agentic RL / 强化学习框架】Molt 设计解读
人工智能·算法·机器学习
hahaha60161 天前
HLS高层次综合设计技巧--C++类和模板
图像处理·人工智能·算法·计算机视觉
多弗朗皮卡丘1 天前
算法详解4:买卖股票的最佳时机系列(上)
算法
维克兜率天2 天前
【维克】动量指标家族:RSI、ROC、CCI、Momentum全面解析
python·算法