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操作Excel之POI简单例子
/** * 利用POI操作Excel表单 * * 需要jar包: * HSSF针对03及以前版本,即.xls后缀 * |---poi-3.16.jar * XSSF针对07及以后版本,即xlsx后缀 ...
- 精心整理的SQL语句学习大全
-语 句 功 能 --数据操作SELECT --从数据库表中检索数据行和列INSERT --向数据库表添加新数据行DELETE --从数据库表中删除数据行UPDATE --更新数据库表中的数据-数据 ...
- quartz任务调度初次使用记录
近期公司开发的数据交换系统嵌入了quartz任务调度功能,大概了解了任务调度的整个流程,项目中需要用到它来进行定时任务操作,对数据定时检查以及及时交换. Quartz是OpenSymphony开源组织 ...
- Freetype 安装时提示 make: Nothing to be done for `unix'
[Software-Freetype] Freetype 安装时提示 make: Nothing to be done for `unix' 官网下载的第三方软件包,编译安装会报以下错误,解决办法如下 ...
- js 数组对象去重
let hash = {}; let config = [ { name: 2, state: true, output: 'Y'}, { name: 3, state: true, output: ...
- mysql对库,表,数据类型的操作以及完整性约束
一丶对库的操作 求救语法: help create database; 1.创建数据库 CREATE DATABASE 数据库名 charset utf8; 2.数据库的命名规则: 可以由字母.数字. ...
- 多个图标图片(雪碧图)使用CSS样式显示
现在的网页中显示很多图标算是常态,发现项目中页面上用到的图标都是单个图标单个文件,用的时候直接往页面上挂,这确实很常态. 如果,网站是挂在外网上,或者网速过低,又大量使用图标的情况下,由于浏览器和服务 ...
- 解决perl: warning: Setting locale failed.
在Ubuntu Server 12.04上执行apt-get install命令时,报如下warning 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...
- [转]Git之忽略文件(ignore file)
原文链接:http://blog.csdn.net/benkaoya/article/details/7932370 .gitignore 配置文件用于配置不需要加入版本管理的文件,配置好该文件可以为 ...
- SQL Server 删除当前数据库中所有数据库 ,无视约束
Sql Server中清空所有数据表中的记录 清空所有数据表中的记录: exec sp_msforeachtable @Command1 ='truncate table ?' 删除所有数据表: e ...