LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.2MB, accepted 2025-12-29.

python
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

Source