748. Shortest Completing Word
https://leetcode.com/problems/shortest-completing-word/description/
class Solution {
public:
string shortestCompletingWord(string licensePlate, vector<string>& words) {
int cnt = 0;
vector<int> dict(26,0);
for (auto c : licensePlate) {
if (isupper(c)) { cnt++; dict[c-'A']++; }
if (islower(c)) { cnt++; dict[c-'a']++; }
}
string res;
for (int i = 0; i < words.size(); i++) {
const auto& w = words[i];
vector<int> dictTemp = dict;
int cntTemp = cnt;
for (auto c : w) {
if (dictTemp[c-'a'] > 0) {
dictTemp[c-'a']--;
cntTemp--;
}
}
if (cntTemp == 0) {
if (res.length() == 0 || res.length() > w.length())
res = w;
}
}
return res;
}
};
748. Shortest Completing Word的更多相关文章
- 【Leetcode_easy】748. Shortest Completing Word
problem 748. Shortest Completing Word 题意: solution1: class Solution { public: string shortestComplet ...
- LeetCode 748 Shortest Completing Word 解题报告
题目要求 Find the minimum length word from a given dictionary words, which has all the letters from the ...
- [LeetCode&Python] Problem 748. Shortest Completing Word
Find the minimum length word from a given dictionary words, which has all the letters from the strin ...
- leetcode 748. Shortest Completing Word
Find the minimum length word from a given dictionary words, which has all the letters from the strin ...
- 【LeetCode】748. Shortest Completing Word 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- [LeetCode] Shortest Completing Word 最短完整的单词
Find the minimum length word from a given dictionary words, which has all the letters from the strin ...
- LeetCode算法题-Shortest Completing Word(Java实现)
这是悦乐书的第309次更新,第330篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第178题(顺位题号是748).从给定的字典单词中查找最小长度单词,其中包含字符串lic ...
- [Swift]LeetCode748. 最短完整词 | Shortest Completing Word
Find the minimum length word from a given dictionary words, which has all the letters from the strin ...
- LeetCode All in One题解汇总(持续更新中...)
突然很想刷刷题,LeetCode是一个不错的选择,忽略了输入输出,更好的突出了算法,省去了不少时间. dalao们发现了任何错误,或是代码无法通过,或是有更好的解法,或是有任何疑问和建议的话,可以在对 ...
随机推荐
- 利用Java程序将字符串进行排序与拼接
1.初始生成字符串的代码程序: package com.map.test; import java.util.ArrayList; import java.util.Collections; impo ...
- Java 多线程的实现方法
package com.jckb; /**多线程实现的两种方法 * * @author gx * */ public class Test2 { public static void main(Str ...
- SQL Server收缩数据库
USE[master]GOALTER DATABASE CCPG_SFY SET RECOVERY SIMPLE WITH NO_WAITGOALTER DATABASE CCPG_SFY SET R ...
- babel7中 preset-env 完全使用
babel7中 preset-env 完全使用 const presets = [ ['@babel/env', { // chrome, opera, edge, firefox, safari, ...
- This is your path and you will pursue it with excellence.
This is your path and you will pursue it with excellence.自己选的路就要走出精彩.
- 使用HTML5 canvas做地图(1)基础知识
之前一直想使用HTML5技术全新做一套地图API,可是苦于时间和精力,迟迟未有行动.后来下定决心,利用下班和周末做出一个大体框架出来,现在和网友分享一下自己的整体的一个思路和想法.欢迎大家提出宝贵建议 ...
- LaTeX 符号大全
常用数学符号的 LaTeX 表示方法 2016-10-31 16:22 | 黄荣生 常用数学符号的 LaTeX 表示方法 1.指数和下标可以用^和_后加相应字符来实现.比如: 2.平方根(squa ...
- C# sftp通过秘钥上传下载
一.适用场景 我们平时习惯了使用ftp来上传下载文件,尤其是很多Linux环境下,我们一般都会通过第三方的SSH工具连接到Linux,但是当我们需要传输文件到Linux服务器当中,很多人习惯用ftp来 ...
- 第1章 .Net应用程序体系结构
1. CLR:公共语言运行库,是每种.Net编程语言都使用的运行库 Windows 8为Windows Store应用程序引入了一个新的编程接口:Windows运行库. C# 6 具有许多小而实用的语 ...
- Java static修饰符小记
首先我们明确一点:java是一个纯面向对象的编程语言,它的每一个文件都视为一个类,当我们创建一个对象的时候,就是在调用一个文件,那么这个时候,这个文件(类)里的一些东西,它是需要通过对象来使用或访问, ...