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们发现了任何错误,或是代码无法通过,或是有更好的解法,或是有任何疑问和建议的话,可以在对 ...
随机推荐
- mysql数据库忘记密码时如何修改(一)
方法/步骤 打开mysql.exe和mysqld.exe所在的文件夹,复制路径地址 打开cmd命令提示符,进入上一步mysql.exe所在的文件夹. 输入命令 mysqld --skip-grant ...
- Sql server 数据库的备份和还原数据库提示“ 加载的介质已格式化为支持 1 个介质簇,但根据指定的备份设备,应支持 2 个介质簇”
数据库备份和还原总结 在 "M:\2017-Pro\company\other\databak_2014-10\anquanbaowei_db_201704300200.BAK" ...
- Vue小贴士
1.去掉空格影响,删除掉此段代码 2.想要同时运行两个Vue项目,修改端口号,黄色框内的内容自己随意改个端口号就行,比如:8082 3.批处理 在项目的根目录中添加a.bat文件,这样就可以在运行的 ...
- 从零开始的全栈工程师——js篇2.7(JS数据类型具体分析)
JS数据类型具体分析与数据的三大存储格式 1. 字符串 string2. 数字 number3. 布尔 boolean4. null 空5. undefined 未定义↑↑↑叫基本数据类型 基本数据类 ...
- while循环,break和continue,运算符,格式化输出
一丶while循环 while条件: 代码块(循环体) #数数 打印1-100 count = 1 while count <= 100: print(count) count += 1 执行顺 ...
- sublimetext3安装配置
官网:http://www.sublimetext.com/ 中文官网:http://www.sublimetextcn.com/ 包管理器:https://packagecontrol.io/ins ...
- python 多线程 生产者消费者
import threading import time import logging import random import Queue logging.basicConfig(level=log ...
- vue-初识
一:vue基础1.1.Vue是一套构建用户界面的渐进式框架1.2.引入vue:<script src="https://unpkg.com/vue/dist/vue.js"& ...
- linux 命令——42 kill (转)
Linux 中的kill命令用来终止指定的进程(terminate a process)的运行,是Linux下进程管理的常用命令.通常,终止一个前台进程可以 使用Ctrl+C键,但是,对于一个后台进程 ...
- UVALive 4727 Jump(约瑟夫环,递推)
分析: 如果问题是要求最后一个删除的数,重新编号为0到n-1,f[n]表示答案,那么f[n] = (f[n-1]+k)%n. 因为删掉下标k-1以后可以从下标k重新编号为0. 在这个问题只需要推出最后 ...