One question daily 2299. Code inspection device II
Excess when executing100%User,What can I say about this question,But oneBit operationKnowledge point
My code:
class Solution:
def strongPasswordCheckerII(self, password: str) -> bool:
flag1 = flag2 = flag3 = flag4 = 1
ret = None
for i in password:
if ret == i:
return False
if i.isdigit():
flag1 = 0
elif i.isupper():
flag2 = 0
elif i.islower():
flag3 = 0
else:
flag4 = 0
ret = i
if sum([flag1, flag2, flag3, flag4]) == 0 and len(password) >= 8:
return True
return FalseBit operation代码:
method one:simulation + Bit operation
According to the description of the topic,我们可以simulation检查密码是否满足题目要求的过程。
first,We check whether the length of the password is less than 8,in the case of,Then return false。
Next,We use a mask mask To record whether the password contains a lowercase letter、uppercase letter、Numbers and special characters。We traverse the password,Like a character every time,First determine whether it is the same as the previous character,in the case of,Then return false。Then,Update mask according to the type of character mask。at last,We check the mask mask Whether it is 15,in the case of,Then return true,否Then return false。
class Solution:
def strongPasswordCheckerII(self, password: str) -> bool:
if len(password) < 8:
return False
mask = 0
for i, c in enumerate(password):
if i and c == password[i - 1]:
return False
if c.islower():
mask |= 1
elif c.isupper():
mask |= 2
elif c.isdigit():
mask |= 4
else:
mask |= 8
return mask == 15author:ylb Link:https://leetcode.cn/problems/strong-password-checker-ii/solutions/2068878/by-lcbin-hk2a/
贡献者
最近更新
Involution Hell© 2026 byCommunityunderCC BY-NC-SA 4.0
One question daily 2293. Great mini game
LeetCode 2293. 极大极小游戏 题解 — 通过递归思想将一维数组不断转化为二维数组操作,避免索引变化混乱;利用 flag 计数交替取最大值与最小值,适合正在刷简单题、巩固递归与数组处理技巧的算法初学者。
2309. The best English letters with both appropriates and lowercases One question daily
LeetCode 2309. 兼具大小写的最好英文字母 题解 — 使用哈希表与位运算两种解法,哈希表法从 Z 开始逆序查找字母是否同时出现大小写,位运算法用两个整数掩码分别记录小写和大写字母出现情况,再通过与运算找出最高位对应字母。适合正在刷 LeetCode 每日一题、想掌握哈希表与位运算技巧的求职者和算法学习者。