Add C++ solution: 420. Strong Password Checker #516
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Add a C++ solution for LeetCode 420 – Strong Password Checker.
Problem: https://leetcode.com/problems/strong-password-checker/
Language: C++
File path:
C++/420-strong-password-checker.cpp
Approach (summary):
max(missing, 6 - n)
.max(missing, totalReplacements)
.del = n - 20
characters; spend deletions to reduce replacements:len % 3 == 0
,len % 3 == 1
,Final answer =
deletions + max(missing, replacementsAfterDeletions)
.Time Complexity:
O(n)
Space Complexity:
O(k)
for run tracking (≤O(n)
in worst case)Difficulty: Hard
Tags: Greedy, Strings
Put check marks:
C++
folder).How Has This Been Tested?
"a"
→5
"aA1"
→3
"ABABABABABABABABABAB1a"
→2
0
.Checklist