2391. Strong Password Checker II
My accepted Python solution to LeetCode problem 2391, Strong Password Checker II, running in 0ms.
- Difficulty: Easy
- Python
- Runtime 0ms
- Memory 17.2MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.2MB, accepted 2025-12-29.
class Solution:
def strongPasswordCheckerII(self, password: str) -> bool:
if len(password) < 8:
return False
has_lower = any(c.islower() for c in password)
has_upper = any(c.isupper() for c in password)
has_digit = any(c.isdigit() for c in password)
has_special = any(c in "!@#$%^&*()-+" for c in password)
# Check for adjacent same characters
has_adjacent = any(password[i] == password[i+1] for i in range(len(password)-1))
return has_lower and has_upper and has_digit and has_special and not has_adjacent