【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 ...
随机推荐
- 后端token认证模板
1.创建一个视图 from rest_framework import exceptions from app01 import models from rest_framework.authenti ...
- DOM属性获取、设置、删除
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 题解 [51nod1225]余数之和
题解 [51nod1225]余数之和 题面 解析 首先可以发现,\(a\)%\(b\)\(=a-b*\lfloor a/b \rfloor\). 而对于一段连续的\(b\)来说\(\lfloor a/ ...
- Appium自动化测试教程-自学网-monkey自定义脚本实践
自定义脚本的稳定性测试 常规Monkey测试执行的是随机的事件流,但如果只是想让Monkey测试某个特定场景这时候就需要用到自定义脚本了,Monkey支持执行用户自定义脚本的测试,用户只需要按照Mon ...
- java 数组对象的应用
public class Student 2 { 3 // 成员变量 4 private String name; 5 private int age; 6 7 // 构造方法 8 public St ...
- Spring security invalid-session-url 的坑(配了permitAll仍然跳转到登录页)
Spring security session配置中如果配了如下的invalid-session-url,配置了permitAll链接首次链接系统时会跳转到登录页,将该配置删除即可解决此问题. < ...
- Linux操作系统常用命令合集——第五篇-磁盘和文件系统操作(15个命令)
1.fdisk [命令作用] 用于观察硬盘实体使用情况.也可以对硬盘分区. 对于一块硬盘来讲,最多只能管理15个分区 [命令语法] fidisk [选项] [参数] [常用选项] -b& ...
- 5.Python3列表和元组
5.1序列 在python3中序列结构主要有列表.元组.集合.字典和字符串,对于这些序列有以下通用操作. 5.1.1 索引 序列中的每一个元素都有 一个编号,也称为索引.这个索引是从0开始递增的,即下 ...
- Python里面如何实现tuple和list的转换?
#list to tuple lis=[,,,,,] x=tuple(lis) print(type(x),x) #tuple to list tup=(,,,,,) y=list(tup) prin ...
- 卸载ros
#卸载 ros sudo apt-get autoremove ros-*