Leetcode - Count and Say
38. Count and Say[E]
https://leetcode.com/problems/count-and-say/
Description
The count-and-say sequence is the sequence of integers with the first five terms as following:
1 | 1. 1 |
1 is read off as "one 1" or 11.
11 is read off as "two 1s" or 21.
21 is read off as "one 2, then one 1" or 1211.
Given an integer n where 1 ≤ n ≤ 30, generate the nth term of the count-and-say sequence. You can do so recursively, in other words from the previous member read off the digits, counting the number of digits in groups of the same digit.
Note: Each term of the sequence of integers will be represented as a string.
Example 1:
1 | Input: 1 |
Example 2:
1 | Input: 4 |
Solution
https://leetcode.com/problems/count-and-say/discuss/16015/Please-change-the-misleading-description
https://leetcode.com/problems/count-and-say/discuss/15999/4-5-lines-Python-solutions
1 | class Solution: |
443. String Compression[E]
https://leetcode.com/problems/string-compression/
Description
Given an array of characters, compress it in-place.
The length after compression must always be smaller than or equal to the original array.
Every element of the array should be a character (not int) of length 1.
After you are done modifying the input array in-place, return the new length of the array.
Follow up:
Could you solve it using only O(1) extra space?
Example 1:
1 | Input: |
Example 2:
1 | Input: |
Example 3:
1 | Input: |
Note:
- All characters have an ASCII value in
[35, 126]. 1 <= len(chars) <= 1000.
Solution
1 | class Solution: |





