StrengthOfPassword
Last updated
Was this helpful?
Last updated
Was this helpful?
这道题 但是细节稍有不同 这题用nested for loop就可以解但会有test cases超时 需要用DP比较快就全能过了.
*
Approach: Take all possible sub-strings of the given string and use a to check whether the current sub-string has been processed before. Now, for every distinct sub-string, count the distinct characters in it (again set can be used to do so). The sum of this count for all the distinct sub-strings is the final answer. Below is the implementation of the above approach:
Idea : counting the contribution by each alphabet to the answer i.e, If a substring has multiple a's, only '1' is contributed by 'a' to the final count per each substring.
Version 2: