当前位置:网站首页>Leetcode 1170. Frequency of occurrence of the minimum letter of the comparison string (yes, solved)
Leetcode 1170. Frequency of occurrence of the minimum letter of the comparison string (yes, solved)
2022-06-26 16:47:00 【I'm not xiaohaiwa~~~~】

Define a function f(s), Statistics s in ( Compare in dictionary order ) The frequency of the smallest letter , among s Is a non empty string .
for example , if s = “dcce”, that f(s) = 2, Because the smallest letter in the dictionary order is “c”, It appears 2 Time .
Now? , Here are two string arrays to look up queries And vocabulary words . For each query queries[i] , Statistics required words Meet in f(queries[i]) < f(W) Of The number of words ,W Represents a vocabulary words Every word in .
Please return an integer array answer As the answer , Each of them answer[i] It's No i Results of this query .
Example 1:
Input :queries = ["cbd"], words = ["zaaaz"]
Output :[1]
explain : Inquire about f("cbd") = 1, and f("zaaaz") = 3 therefore f("cbd") < f("zaaaz").
Example 2:
Input :queries = ["bbb","cc"], words = ["a","aa","aaa","aaaa"]
Output :[1,2]
explain : First query f("bbb") < f("aaaa"), The second query f("aaa") and f("aaaa") all > f("cc").
Tips :
- 1 <= queries.length <= 2000
- 1 <= words.length <= 2000
- 1 <= queries[i].length, words[i].length <= 10
- queries[i][j]、words[i][j] It's all made up of lowercase letters
Code:
class Solution {
public:
vector<int> numSmallerByFrequency(vector<string>& queries, vector<string>& words) {
vector<int>vecword;
for(int i=0;i<words.size();i++)
{
string temp=words[i];
sort(temp.begin(),temp.end());
vecword.push_back(count(temp.begin(),temp.end(),temp[0]));
}
sort(vecword.begin(),vecword.end());
vector<int>res;
for(int i=0;i<queries.size();i++)
{
string temp=queries[i];
sort(temp.begin(),temp.end());
int cnt=count(temp.begin(),temp.end(),temp[0]);
int ans=0;
ans=count_if(vecword.begin(),vecword.end(),[=](int a){
return a>cnt;});
res.push_back(ans);
}
return res;
}
};
边栏推荐
- Redis Guide (8): principle and implementation of Qianfan Jingfa distributed lock
- Make up the weakness - Open Source im project openim about initialization / login / friend interface document introduction
- Which position does Anxin securities rank? Is it safe to open an account?
- Constructors and Destructors
- 100+数据科学面试问题和答案总结 - 基础知识和数据分析
- JS tutorial - printing stickers / labels using the electronjs desktop application
- Teach you to learn dapr - 9 Observability
- Cloud platform monitoring system based on stm32+ Huawei cloud IOT design
- Count the number of each vowel letter in the string
- Teach you to learn dapr - 3 Run the first with dapr Net program
猜你喜欢

C language --- basic function realization of push box 01

Kubecon China 2021 Alibaba cloud special session is coming! These first day highlights should not be missed

Teach you to learn dapr - 8 binding

Teach you to learn dapr - 1 The era of net developers

Teach you to learn dapr - 5 Status management

基于STM32+华为云IOT设计的云平台监控系统

无需人工先验!港大&同济&LunarAI&旷视提出基于语义分组的自监督视觉表征学习,显著提升目标检测、实例分割和语义分割任务!...

r329(MAIX-II-A(M2A)资料汇总

Interpretation of new plug-ins | how to enhance authentication capability with forward auth

Science | 红树林中发现的巨型细菌挑战传统无核膜观念
随机推荐
No manual prior is required! HKU & Tongji & lunarai & Kuangshi proposed self supervised visual representation learning based on semantic grouping, which significantly improved the tasks of target dete
JS tutorial - printing stickers / labels using the electronjs desktop application
Leetcode 1170. 比较字符串最小字母出现频次(可以,已解决)
架构实战营毕业设计
Screenshot of the answers to C language exercises
IAR engineering adapts gd32 chip
I regard it as a dry product with a monthly income of more than 30000 yuan for sidelines and more than 10000 yuan for novices!
探讨:下一代稳定币
STM32F103C8T6实现呼吸灯代码
Scala 基础 (二):变量和数据类型
Arduino uno + DS1302 simple time acquisition and serial port printing
C语言 头哥习题答案截图
Notes on key review of software engineering at the end of the term
安信证券排名第几位?开户安全吗?
Greenplum数据库故障分析——semop(id=2000421076,num=11) failed: invalid argument
无需人工先验!港大&同济&LunarAI&旷视提出基于语义分组的自监督视觉表征学习,显著提升目标检测、实例分割和语义分割任务!...
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
y=1/100*100+1/200*200+1/300*300+.....+ 1/m*m
Mono 的一些实例方法
【小5聊】毕业8年,一直在追梦的路上