To the Top
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 | 327 Views, 20852 Search Bots | 87 Words

Subscribe to Feed Burner | 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:


class Solution(object):
def compress(self, chars):
# Fill this in.

print Solution().compress(['a', 'a', 'b', 'c', 'c', 'c'])
# ['a', '2', 'b', 'c', '3']
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 327 Views, 20852 Search Bots | 87 Words Subscribe to Feed Burner

Related Articles

  1. Daily Interview Problem: Trapping Rainwater
  2. Spreadsheet Column Title
  3. CPU Utilization
  4. New Vulnerabilities (CVE-2016-4581) have been detected in CentOS/RHEL/CloudLinux 7
  5. Consecutive Ones
  6. Daily Interview Problem: Find the Number of Islands
  7. Daily Interview Problem: Get all Values at a Certain Height in a Binary Tree
  8. Algorithm Interview: Longest Consecutive Sequence
  9. Daily Interview Problem: Reconstrunct Binary Tree from Preorder and Inorder Traversals
  10. [Daily Problem] Remove k-th Last Element From Linked List

Comments (0)

Your Email (Domain Part Not Exposed):

Your Comments:

Privately By Mail Colors More Smileys S x y @

Verification (Click Image 2 Refresh):

    Be the first one to comment this page !


Page Edited: May 11 2024 14:36:49 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />