File: root - text - article - 2020 - 01 - string-compression.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 566 Views, 24263 Search Bots | 87 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 566 Views, 24263 Search Bots | 87 Words
| Browse | Archive
Hi, here's your problem today. This problem was recently asked by Twitter:
Given an array of characters with repeats, compress it in place. The length after compression should be less than or equal to the original array.
Example:
Input: ['a', 'a', 'b', 'c', 'c', 'c']
Output: ['a', '2', 'b', 'c', '3']
Here's a starting point:
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 566 Views, 24263 Search Bots | 87 Words Given an array of characters with repeats, compress it in place. The length after compression should be less than or equal to the original array.
Example:
Input: ['a', 'a', 'b', 'c', 'c', 'c']
Output: ['a', '2', 'b', 'c', '3']
Here's a starting point:
class Solution(object):
def compress(self, chars):
# Fill this in.
print Solution().compress(['a', 'a', 'b', 'c', 'c', 'c'])
# ['a', '2', 'b', 'c', '3']
Related Articles
- Daily Interview Problem: Queue Using Two Stacks
- Daily Interview Problem: Distribute Bonuses
- A trick for getting good at coding interviews FASTER
- Daily Interview Problem: Reverse Words in a String
- Daily Interview Problem: Look and Say Sequence
- [Daily Problem] Add two numbers as a linked list
- Absolute Path
- Daily Interview Problem: Count Number of Unival Subtrees
- Plus One
- Algorithm Interview Question: Nth Fibonacci Number
©2006~2024 SteakOverCooked - 0.01431 Seconds(s) - 1355.245 KB/s - 28 Online Memory: 492.38 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
How to Cook a Perfect Steak? | <meta name="robots" content="index, follow">
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Comments (0)
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !