【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 ...
随机推荐
- Django中出现:TemplateDoesNotExist at
setting文件中加入:
- Oracle的dual是什么东西啊??(答:伪表)
1. dual 确实是一张表.是一张只有一个字段,一行记录的表.2.习惯上,我们称之为'伪表'.因为他不存储主题数据.3. 他的存在,是为了操作上的方便.因为select 都是要有特定对象的.如:se ...
- yy
sudo rm -rf /var/cache/apt/archives/python-catkin-pkg-modules_0.4.12-1_all.deb sudo rm -rf /var/cach ...
- Linux下基于Xampp的TestLink的安装部署
由于项目需要,故需要搭建Testlink,且出于稳定,考虑在linux环境部署,当然windows系统也是可以的. 系统:64位操作系统 linux:centos6.8 testlink:1.9.14 ...
- Java基础系列 - 抽象类,子类继承
package com.company; /** * 抽象类继承 * 用abstract修饰类就是抽象类 * 用abstract修饰方法就是抽象方法(一般使用比较少) * 抽象类不能被实例化 */ p ...
- known_hosts有什么用?
一.问题描述 当我连接我的服务器的时候,返回信息如下 二.问题分析 返回的信息是什么意思? IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! ...
- 学习笔记:Linux下共享内存的方式实现进程间的相互通信
一.常用函数 函数系列头文件 #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> ft ...
- Cookie 概述
一.属性介绍 Name Cookie的key Value Cookie的value Domain 可以访问此Cookie的域名 Path 可以访问此Cookie的页面路径 Expires/Max-Ag ...
- js的基本数据类型
Undefined.Null.Boolean.Number.String.ECMAScript 2015 新增:Symbol(创建后独一无二且不可变的数据类型 )
- Python-文件读写及修改
文件的读写有三种形式:读.写和追加. 一.读模式 r 和读写模式 r+ 1.读模式 r 读模式r特点:(1)只能读,不能写:(2)文件不存在时会报错. (1)例:读取当前目录下的books.txt文件 ...