For the best experience, increase the window size or view on a laptop or desktop device
Title | ||
|---|---|---|
Loading... | ||
For the best experience, increase the window size or view on a laptop or desktop device
Title | ||
|---|---|---|
Loading... | ||
countAndSay(s) is the way you would "say" the digit string s.
To determine how you "say" a digit string, split it into the minimal number of substrings such that each substring contains exactly one unique digit. Then for each substring, say the number of digits, then say the digit. Finally, concatenate every said digit.
For example, countAndSay("3322251") is two '3's, three '2's, one '5', and one '1'.
Given a digit string s, return the count-and-say sequence you get from s.
Example 1:
countAndSay('1') = '11'
Example 2:
countAndSay("1211") = "111221"
Now let's think about the reversal of count_and_say function. reverse_count_and_say(s) is a function that takes a digit string s and returns all the possible digit strings which would generate s as their count-and-say sequence. For example, let s = '123', then the reverse count-and-say sequence of s would be ['23', '333333333333'] because the count-and-say sequence of 23 is 123 (one '23') and the count-and-say sequence of 333333333333 is also 123 (twelve '3's). How would you implement the reverse count-and-say algorithm?
countAndSay(s) is the way you would "say" the digit string s.
To determine how you "say" a digit string, split it into the minimal number of substrings such that each substring contains exactly one unique digit. Then for each substring, say the number of digits, then say the digit. Finally, concatenate every said digit.
For example, countAndSay("3322251") is two '3's, three '2's, one '5', and one '1'.
Given a digit string s, return the count-and-say sequence you get from s.
Example 1:
countAndSay('1') = '11'
Example 2:
countAndSay("1211") = "111221"
Now let's think about the reversal of count_and_say function. reverse_count_and_say(s) is a function that takes a digit string s and returns all the possible digit strings which would generate s as their count-and-say sequence. For example, let s = '123', then the reverse count-and-say sequence of s would be ['23', '333333333333'] because the count-and-say sequence of 23 is 123 (one '23') and the count-and-say sequence of 333333333333 is also 123 (twelve '3's). How would you implement the reverse count-and-say algorithm?
Output