【Leetcode_easy】748. Shortest Completing Word
problem
题意:
solution1:
class Solution {
public:
string shortestCompletingWord(string licensePlate, vector<string>& words) {
string res = "";
unordered_map<char, int> freq;
int total = ;
for(char ch : licensePlate)
{
if(ch>='a' && ch<='z') { freq[ch]++; total++; }
else if(ch>='A' && ch<='Z') { freq[ch+]++; total++; }
}
for(auto word:words)
{
int cnt = total;
unordered_map<char, int> t = freq;
for(auto ch:word)
{
if(t[ch] > ) { cnt--; t[ch]--; }//err...
}
if(cnt== && (res.empty() || res.size()>word.size())) res = word;
}
return res;
}
};
solution2:
参考
1. Leetcode_easy_748. Shortest Completing Word;
2. Grandyang;
完
【Leetcode_easy】748. Shortest Completing Word的更多相关文章
- 【LeetCode】748. Shortest Completing Word 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 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_easy】821. Shortest Distance to a Character
problem 821. Shortest Distance to a Character solution1: class Solution { public: vector<int> ...
- 【Leetcode_easy】819. Most Common Word
problem 819. Most Common Word solution: class Solution { public: string mostCommonWord(string paragr ...
- 【leetcode_easy】581. Shortest Unsorted Continuous Subarray
problem 581. Shortest Unsorted Continuous Subarray 题意:感觉题意理解的不是非常明白. solution1: 使用一个辅助数组,新建一个跟原数组一模一 ...
- 748. Shortest Completing Word
https://leetcode.com/problems/shortest-completing-word/description/ class Solution { public: string ...
- LeetCode算法题-Shortest Completing Word(Java实现)
这是悦乐书的第309次更新,第330篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第178题(顺位题号是748).从给定的字典单词中查找最小长度单词,其中包含字符串lic ...
随机推荐
- 为 32 位单片机设计的脚本语言 Berry
Berry是一款一款为32位单片机设计的脚本语言.Berry解释器使用C89标准实现,该语言可以在RAM或ROM很小的设备上运行. 尽管Berry的体积很小,但是它也支持class以及闭包等功能,使得 ...
- AirtestIde的安装(win10)
Airtest 是网易出品的一款基于图像识别和poco控件识别的一款UI自动化测试工具. Airtest IDE是这个项目的一个IDE,就像Eclipse.Pycharm一样,是一个集成开发工具. A ...
- Vue多语言支持
i18n插件实现多语言支持,本文以中英文为例记录一下配置过程. 1.配置 1.1安装:npm install vue-i18n --save 1.2创建中英文配置项文件 src/lang目录下创建以下 ...
- 07_gitee源码参考
Django REST framework Tutorial 教程 码云:https://gitee.com/venicid/tutorial-api
- 去除IDEA中xml黄色背景
idea版本:IntelliJ IDEA 2019.2.1 在编写mybatis的xml中会出现大面积黄色背景提示,看起来比较不舒服. 去掉黄色背景颜色 1.打开File->Settings-& ...
- git致命错误汇总
1. 拒绝合并无关历史 fatal: refusing to merge unrelated histories 解决办法: git pull origin master --allow-unrel ...
- CF798D Mike and distribution 贪心
我感觉这道题挺神的~ 假设 $a[i]=b[i]$,那么我们可以将 $a$ 降序排序,然后你发现只要你按照 $1,3,5......n$ 这么取一定是合法的. 而我们发现 $2$ 比取 $3$ 优,取 ...
- 对拍——>bat
为了凸显对拍滴重要性.就拿来当置顶啦! ——本来是那样想的 ---------------------------------------------------------------------- ...
- javaee三层架构案例--简单学生管理系统
背景 学了jdbc.jsp等需要串起来,不然会忘记 项目环境 win10 jdk11 mysql8.0.13 jar包 c3p0-0.9.5.2 commons-dbutils-1.7 jstl mc ...
- meshing-划分圆柱结构化网格
原视频下载地址:https://yunpan.cn/cqjeckrzEpVkY 访问密码 eb5d