Weekly #10

@Date : 2019-06-03 09:06:37

@Author : Lewis Tian (taseikyo@gmail.com)

@Link : https://taseikyo.github.io

@Range : 2019/06/03 - 2019/06/09

Weekly #10 Photo by Stefan Spassov on Unsplash

Table of Contents

algorithm

1002. Find Common Characters

Easy

Given an array A of strings made only from lowercase letters, return a list of all characters that show up in all strings within the list (including duplicates). For example, if a character occurs 3 times in all strings but not 4 times, you need to include that character three times in the final answer.

You may return the answer in any order.

Example 1:

Input: ["bella","label","roller"]
Output: ["e","l","l"]
Example 2:

Input: ["cool","lock","cook"]
Output: ["c","o"]

Note:

  • 1 <= A.length <= 100
  • 1 <= A[i].length <= 100
  • A[i][j] is a lowercase letter

solution

Easy in Python, just one line.

class Solution:
    def commonChars(self, A: List[str]) -> List[str]:
        '''40 ms 99.38%    13.4 MB'''
        return [i for i in reduce(and_, [set(i) for i in A]) for j in range(min(k.count(i) for k in A))]

review

This article discusses the issue of "Running Axon Server on Kubernetes or virtual machines."

Each method has several advantages and disadvantages, but I think it's better to use virtual machines.

tip

This article discusses the problem of 'an array of length 0 in C'.

share

This article introduces the memory allocation and management of Linux and is worth reading.

results matching ""

    No results matching ""