Leetcode - String Compression - Javascript Solution

preview_player
Показать описание
In this video we are solving another coding challenge on Leetcode, called String Compression using javascript:

Given an array of characters chars, compress it using the following algorithm:

Begin with an empty string s. For each group of consecutive repeating characters in chars:

If the group's length is 1, append the character to s.
Otherwise, append the character followed by the group's length.
The compressed string s should not be returned separately, but instead be stored in the input character array chars. Note that group lengths that are 10 or longer will be split into multiple characters in chars.

After you are done modifying the input array, return the new length of the array.


Follow up:
Could you solve it using only O(1) extra space?

Here's the link to the coding challenge.

#leetcodestringcompression #stringcompressionjavascript #leetcode #coding #codingchallenges
Рекомендации по теме
Комментарии
Автор

Hello everyone! If you have a suggestion for a next video please don't hesitate to comment. Also if you have any questions about the solution I'm here to answer them!

TheCodingOdyssey