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;
      }

    };

相关推荐
郝学胜-神的一滴19 小时前
Effective STL 条款 07:指针容器销毁前先删除
开发语言·c++·vscode·leetcode·rpc·visual studio
CoderYanger19 小时前
A.每日一题:2243. 计算字符串的数字和
java·开发语言·程序人生·leetcode·面试·蓝桥杯·学习方法
青少儿编程课堂1 天前
蓝桥杯真题解析:三维偏序的CDQ分治(全国青少年信息素养大赛与电子学会编程考级)
c++·python·算法·bfs·信息学竞赛
Navigator_Z1 天前
LeetCode //C - 1323. Maximum 69 Number
c语言·算法·leetcode
geovindu1 天前
python:Lasso
开发语言·后端·python·算法
AAA修煤气灶刘哥1 天前
同一个模型,为什么还要专门练一遍怎么用工具?
人工智能·后端·算法
AAA修煤气灶刘哥1 天前
两个 Agent 各自改得都对,合在一起为什么出错?
人工智能·后端·算法
电科_银尘1 天前
【大模型算法与工程 34】QLoRA:量化底座上的低秩训练
人工智能·算法·机器学习
专注仿真1 天前
智能体训练:模仿学习与 MCTS 算法详解与实战
算法·强化学习·仿真·afsim智能体·仿真训练