当前位置:网站首页>6095. 强密码检验器 II
6095. 强密码检验器 II
2022-07-02 12:10:00 【紫菜(Nori)】
循环遍历每个字符判断,对于特殊字符,直接使用一个字符串去存储,利用find方法判断是否存在
class Solution {
public:
bool strongPasswordCheckerII(string password) {
if(password.size() < 8){
return false;
}
// 方便后面判断特殊字符是否存在
string specialStr = "[email protected]#$%^&*()-+";
char prevC = '/', nextC;
// 大写、小写字母、数字、特殊字符
bool lower = false, upper = false, number = false, special = false;
for(int i = 0; i < password.size(); i++){
nextC = password[i];
if(prevC == nextC){
// 连续出现相同字符则直接返回
return false;
}else if('a' <= nextC && 'z' >= nextC){
lower = true;
}else if('A' <= nextC && 'Z' >= nextC){
upper = true;
}else if('0' <= nextC && '9' >= nextC){
number = true;
}else if(!special){
// 记录特殊字符
int ind = specialStr.find(nextC);
// 如果找到则ind为对应位置的下标
if(ind >= 0 && ind < specialStr.size()){
special = true;
}
}
// 记录当前字符
prevC = nextC;
}
return (lower & upper & number & special);
}
};
边栏推荐
猜你喜欢

LeetCode刷题——递增的三元子序列#334#Medium

YOLOV5 代码复现以及搭载服务器运行

Set set you don't know

Oracle primary key auto increment

Solve the problem of frequent interruption of mobaxterm remote connection

06_ Stack and queue conversion

搭建自己的语义分割平台deeplabV3+

Download blender on Alibaba cloud image station

LeetCode刷题——验证二叉树的前序序列化#331#Medium

There are 7 seats with great variety, Wuling Jiachen has outstanding product power, large humanized space, and the key price is really fragrant
随机推荐
【LeetCode】1254-统计封闭岛屿的数量
05_ queue
微信支付宝账户体系和支付接口业务流程
07_ Hash
Set set you don't know
10_Redis_geospatial_命令
[leetcode] 200 number of islands
NBA player analysis
XML Configuration File
FPGA - 7系列 FPGA内部结构之Clocking -03- 时钟管理模块(CMT)
Pytorch 保存tensor到.mat文件
Common English abbreviations for data analysis (I)
高考录取分数线爬取
Bing.com網站
12_ Redis_ Bitmap_ command
LeetCode_ String_ Simple_ 412.Fizz Buzz
4. Jctree related knowledge learning
How to choose a third-party software testing organization for automated acceptance testing of mobile applications
【网络安全】网络资产收集
03_ Linear table_ Linked list