news 2026/5/2 22:14:14

leetcode 3606

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
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<string> validateCoupons(vector<string>& code, vector<string>& businessLine, vector<bool>& isActive) { vector<string> groups[4]; //长度为 4 的数组 vector<string> 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; } };
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/5/2 10:02:04

DAY25 pipeline管道

浙大疏锦行 # 导入基础库 import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns import time # 导入 time 库 import warnings# 忽略警告 warnings.filterwarnings("ignore")# 设置中文字体和负号正常显示 plt.rcParams[…

作者头像 李华
网站建设 2026/4/30 23:19:59

深入理解连接错误:从 “ld returned 1“到系统性解决方案

引言 在C/C程序的构建流程中&#xff0c;链接&#xff08;Linking&#xff09; 是将多个预编译目标文件&#xff08; “.o”/ “.obj”&#xff09;与库文件&#xff08; “.a”/ “.lib”、 “.so”/ “.dll”&#xff09;组合为最终可执行文件或动态库的核心阶段。相较于编译…

作者头像 李华
网站建设 2026/4/30 23:38:20

人工智能之编程基础 Python 入门

前言本章节讲述python的基础数据类型&#xff0c;python的基础数据类型主要包括以下​不可变数据&#xff08;3 个&#xff09;&#xff1a;​Number&#xff08;数字&#xff09;、String&#xff08;字符串&#xff09;、Tuple&#xff08;元组&#xff09;&#xff1b;​可变…

作者头像 李华
网站建设 2026/4/30 23:44:35

GraphQL Editor性能优化实战:5大策略应对大规模Schema挑战

GraphQL Editor性能优化实战&#xff1a;5大策略应对大规模Schema挑战 【免费下载链接】graphql-editor &#x1f4fa; Visual Editor & GraphQL IDE. 项目地址: https://gitcode.com/gh_mirrors/gr/graphql-editor 在处理日益复杂的GraphQL项目时&#xff0c;Sche…

作者头像 李华
网站建设 2026/4/30 23:19:59

8B参数如何超越GPT-4o?揭秘MiniCPM-V 4.5的部署实战

8B参数如何超越GPT-4o&#xff1f;揭秘MiniCPM-V 4.5的部署实战 【免费下载链接】OmniLMM 项目地址: https://gitcode.com/gh_mirrors/om/OmniLMM 你是否曾想过&#xff0c;一个仅有8B参数的开源模型竟然能在多项基准测试中超越GPT-4o-latest这样的顶级闭源模型&#x…

作者头像 李华