当前位置:网站首页>1160. 拼写单词
1160. 拼写单词
2022-08-09 02:22:00 【Mr Gao】
1160. 拼写单词
给你一份『词汇表』(字符串数组) words 和一张『字母表』(字符串) chars。
假如你可以用 chars 中的『字母』(字符)拼写出 words 中的某个『单词』(字符串),那么我们就认为你掌握了这个单词。
注意:每次拼写(指拼写词汇表中的一个单词)时,chars 中的每个字母都只能用一次。
返回词汇表 words 中你掌握的所有单词的 长度之和。
示例 1:
输入:words = [“cat”,“bt”,“hat”,“tree”], chars = “atach”
输出:6
解释:
可以形成字符串 “cat” 和 “hat”,所以答案是 3 + 3 = 6。
示例 2:
输入:words = [“hello”,“world”,“leetcode”], chars = “welldonehoneyr”
输出:10
解释:
可以形成字符串 “hello” 和 “world”,所以答案是 5 + 5 = 10。
解题代码如下:
bool include(int a[],char *b){
int az[26];
for(int i=0;i<26;i++){
az[i]=a[i];
}
for(int i=0;b[i]!='\0';i++){
az[b[i]-'a']--;
if( az[b[i]-'a']<0){
return false;
}
}
return true;
}
int countCharacters(char ** words, int wordsSize, char * chars){
int *r=(int *)malloc(sizeof(int)*26);
for(int i=0;i<26;i++){
r[i]=0;
}
for(int i=0;chars[i]!='\0';i++){
r[chars[i]-'a']++;
}
int len=0;
for(int i=0;i<wordsSize;i++){
if(include(r,words[i])){
len=len+strlen(words[i]);
}
// printf("%s ",words[i]);
}
return len;
}
边栏推荐
- YOLOV1详解——Pytorch版
- Group DETR:分组一对多匹配是加速DETR收敛的关键
- Data recovery software EasyRecovery supports recovery of all types of files
- 2022护眼产品展,北京眼健康展,眼科医学展,近视矫正设备展
- Educational Codeforces Round 132 (Rated for Div. 2)
- 力扣刷题记录4.1-----209. 长度最小的子数组
- 【AspNetCore】实现JWT(使用Microsoft.AspNetCore.Authentication.JwtBearer)
- USB 触摸在竖屏时校准
- 18.flink Table/Sql API之 catlog
- 最强分布式锁工具:Redisson
猜你喜欢
MT4/MQL4入门到精通外汇EA教程第一课 认识MetaEditor
【剑指offer65】不适用加减乘除做加法
终于有人把灰度发布架构设计讲明白了
力扣刷题记录6.1-----203. 移除链表元素
NPDP改版前最后一次考试!请注意
D. Tournament Countdown
Programmer's Daily Life | Daily Fun
HMS Core分析服务智能运营6.5.1版本上线
A40i gxl3680 ts_print报错:tslib: Selected device is not a touchscreen (must support ABS and KEY event
力扣刷题记录5.1-----59. 螺旋矩阵 II
随机推荐
18.flink Table/Sql API之 catlog
2020.10.13开发日志
Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules
SQLite切换日志模式优化
力扣刷题记录3.1-----977. 有序数组的平方
Likou Brush Question Record 5.1-----59. Spiral Matrix II
USB 触摸在竖屏时校准
MT4/MQL4 Getting Started to Mastering EA Tutorial Lesson 1 - MQL Language Common Functions (1) OrderSend() Function
力扣刷题记录6.1-----203. 移除链表元素
ROS2 ERROR: OpenGL 1.5 is not supported in GLRenderSystem::initialiseContext at C:\ci\ws\build...
ROS 、SLAM 学习 error整理
2022 PMP Project Management Certification Exam Registration Guide (1)
.reduce()的简单例子
历史最全DL相关书籍、课程、视频、论文、数据集、会议、框架和工具整理分享
2022杭电多校第五场1007(生成函数+启发式合并+ntt)
帮助安全红队取得成功的11条建议
Difference between KQL and Lucene
史上最猛“员工”,疯狂吐槽亿万富翁老板小扎:那么有钱,还总穿着同样的衣服!
连接数据库且在网页运行的RDLC
2022中国眼博会,中国北京国际儿童青少年眼睛健康产业展览会