Loading...
「ツール」は右上に移動しました。
利用したサーバー: natural-voltaic-titanium
14いいね 1636回再生

Leetcode - String Compression - Javascript Solution

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.

Leetcode - String Compression: leetcode.com/problems/string-compression

#leetcodestringcompression #stringcompressionjavascript #leetcode #coding #codingchallenges

コメント