Leetcode Problem 2299. Strong Password Checker II

2299. Strong Password Checker II

Leetcode Solutions

Iterative Character Checks

  1. Check if the password length is less than 8. If so, return false.
  2. Initialize four boolean variables to false: hasLower, hasUpper, hasDigit, and hasSpecial.
  3. Define a string containing all special characters.
  4. Iterate through each character of the password. a. If the current character is the same as the previous character, return false. b. Check if the current character is a lowercase letter, set hasLower to true. c. Check if the current character is an uppercase letter, set hasUpper to true. d. Check if the current character is a digit, set hasDigit to true. e. Check if the current character is a special character, set hasSpecial to true.
  5. After the iteration, check if all boolean variables are true. If so, return true. Otherwise, return false.
UML Thumbnail

Regex Validation and Iterative Checks

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...