Video description: |
Given a string word, compress it using the following algorithm:
Begin with an empty string comp. While word is not empty, use the follvowing operation:
Remove a maximum length prefix of word made of a single character c repeating at most 9 times.
Append the length of the prefix followed by c to comp.
Return the string comp.
Example 1:
CODEInput: word = "abcde"
Output: "1a1b1c1d1e"
Explanation:
Initially, comp = "". Apply the operation 5 times, choosing "a", "b", "c", "d", and "e" as the prefix in each operation.
For each prefix, append "1" followed by the character to comp.
Example 2:
CODEInput: word = "aaaaaaaaaaaaaabb"
Output: "9a5a2b"
Explanation:
Initially, comp = "". Apply the operation 3 times, choosing "aaaaaaaaa", "aaaaa", and "bb" as the prefix in each operation.
For prefix "aaaaaaaaa", append "9" followed by "a" to comp.
For prefix "aaaaa", append "5" followed by "a" to comp.
For prefix "bb", append "2" followed by "b" to comp.
Constraints:
1 <= word.length <= 2 * 105
word consists only of lowercase English letters.
Solution
Figure out what all repetitions are for this letter, upon understanding this, take into consideration the limit of single character limit (in this case 9).
Now we have
- count and
- letter
Append this and append within the result string.
Here's the Java solution of it
↗ Original-Artikel auf dev.to lesenVollständiger Original-BerichtAusführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
Ähnliche Beiträge
Auch interessante Nachrichten 3163. String Compression III
Thematisch verwandte Begriffe: 3163, String, Compression · 6 Treffer
Getting the Most Out of Transformers in Elastic
KB5121003 Spieleabstürze durch RGB-Treiber beheben - WindowsPower.de
[webapps] C-MOR 6.0104 - Cross-Site Scripting (XSS)
Using LLMs and ESRE to find similar user sessions
Videos werden geladen ...
Beiträge werden geladen ...
Videos werden geladen ...
Beiträge werden geladen ...
Videos werden geladen ...
Beiträge werden geladen ...
Videos werden geladen ...
SOCIAL SHARE CARD GENERATOR