Find the minimum length word from a given dictionary words, which has all the letters from the string licensePlate. Such a word is said to completethe given string licensePlate

Here, for letters we ignore case. For example, "P" on the licensePlate still matches "p" on the word.

It is guaranteed an answer exists. If there are multiple answers, return the one that occurs first in the array.

The license plate might have the same letter occurring multiple times. For example, given a licensePlate of "PP", the word "pair" does not complete the licensePlate, but the word "supper" does.

Example 1:

Input: licensePlate = "1s3 PSt", words = ["step", "steps", "stripe", "stepple"]
Output: "steps"
Explanation: The smallest length word that contains the letters "S", "P", "S", and "T".
Note that the answer is not "step", because the letter "s" must occur in the word twice.
Also note that we ignored case for the purposes of comparing whether a letter exists in the word.

Example 2:

Input: licensePlate = "1s3 456", words = ["looks", "pest", "stew", "show"]
Output: "pest"
Explanation: There are 3 smallest length words that contains the letters "s".
We return the one that occurred first.


  1. licensePlate will be a string with length in range [1, 7].
  2. licensePlate will contain digits, spaces, or letters (uppercase or lowercase).
  3. words will have a length in the range [10, 1000].
  4. Every words[i] will consist of lowercase letters, and have length in range [1, 15].
from collections import Counter
class Solution(object):
def shortestCompletingWord(self, licensePlate, words):
:type licensePlate: str
:type words: List[str]
:rtype: str
a=''.join(l for l in licensePlate.lower() if l.isalpha())
A=[w for w in words if all(Counter(w)[k]>=Counter(a)[k] for k in Counter(a))]
return [w for w in A if len(w)==min(map(len,A))][0]

[LeetCode&Python] Problem 748. Shortest Completing Word More articles about

  1. 【Leetcode_easy】748. Shortest Completing Word

    problem 748. Shortest Completing Word The question : solution1: class Solution { public: string shortestComplet ...

  2. LeetCode 748 Shortest Completing Word Problem solving report

    Subject requirements Find the minimum length word from a given dictionary words, which has all the letters from the ...

  3. leetcode 748. Shortest Completing Word

    Find the minimum length word from a given dictionary words, which has all the letters from the strin ...

  4. [LeetCode&Python] Problem 821. Shortest Distance to a Character

    Given a string S and a character C, return an array of integers representing the shortest distance f ...

  5. 748. Shortest Completing Word class Solution { public: string ...

  6. [LeetCode] Shortest Completing Word The shortest complete word

    Find the minimum length word from a given dictionary words, which has all the letters from the strin ...

  7. LeetCode Algorithm problem -Shortest Completing Word(Java Realization )

    This is the number one of Yuele book 309 Secondary update , The first 330 Original article 01 Reading and preparation Today's presentation is LeetCode Algorithm problem Easy Rank No. 178 topic ( Sequence question no 748). Find the minimum length word from the given dictionary word , It contains the string lic ...

  8. [LeetCode&Python] Problem 720. Longest Word in Dictionary

    Given a list of strings words representing an English Dictionary, find the longest word in words tha ...

  9. [Swift]LeetCode748. The shortest complete word | Shortest Completing Word

    Find the minimum length word from a given dictionary words, which has all the letters from the strin ...

Random recommendation

  1. Linux build Nexus

    Linux install Maven and nexus Agent warehouse 1     explain Environmental Science :redhat Enterprise Linux Server5.3-x64. edition :Maven 3.0.5 ,Nexus-2.5. ...

  2. Bin Packing

    Bin Packing Topic link : subject : A set of  ...

  3. mac svn Terminal operation command

    svn Delete directory command svn Submission of orders svn commit -m zenggui Come out the directory to submit , Press shift + : + q If you don't understand, you can input :svn help For example, you want to query the use of the delete command ...

  4. BZOJ3823 : A token of affection

    n Dimensional hypercube has $2^{n-i}C_n^i$ individual i Dimension element , therefore $O(n)$ Preprocessing 1 To n Inverse element , Again $O(n)$ Calculation is enough . Be careful Trick:P It may be less than n, So let's express the numbers as $a\times P^b$ In the form of . ...

  5. Codeforces Round #337 (Div. 2) C. Harmony Analysis structure

    C. Harmony Analysis Topic linking : Description The semester i ...

  6. sql union Instead of or

    --- original SQL SQL> SELECT deptno FROM emp WHERE empno = 7788 OR job = 'SALESMAN' ORDER BY 1; DEPTNO -- ...

  7. DTD constraint

    DTD constraint One , Import DTD The way   Two ,DTD grammar 2)DTD grammar Constraint labels <!ELEMENT Element name category > or <!ELEMENT The element name ( Element content )> Category : Empty label : ...

  8. C# The six principles of the design pattern ( Reprint )

    Six principles of design pattern ( Reprint ) There is a lot of information about the six design principles of design patterns on the Internet , But the explanation in many places is too general , I also looked for a lot of information to see , Find out CSDN There are several articles on the six principles of design patterns, which are relatively easy to understand , So it's reprinted ...

  9. Installation and use Docker(Windows7)

    1.Boot2Docker Boot2Docker It's the realization of Docker Software for .Windows Under the Docker Only suitable for development testing ( Most people do development testing ..), Not suitable for production environment . Boot2Docker ...

  10. Java Code quality monitoring tools Sonar install

    1.   Seven crimes of code quality Sonar It's a code quality management system . Its help document begins with a clear meaning , Put forward seven crimes of code quality . The summary is quite in place . It's better to have a look : 1.        Bug And hide Bug(Bugs and Pot ...