当前位置:网站首页>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;
}
};
边栏推荐
- 108. 简易聊天室11:实现客户端群聊
- Junit单元测试
- 【小5聊】毕业8年,一直在追梦的路上
- 防火 疏散 自救…这场安全生产暨消防培训干货满满!
- 知道这几个命令让你掌握Shell自带工具
- 内存分区模型
- 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
- Interpretation of new plug-ins | how to enhance authentication capability with forward auth
- Natural language inference with attention and fine tuning Bert pytorch
- Scala 基础 (二):变量和数据类型
猜你喜欢
随机推荐
r329(MAIX-II-A(M2A)资料汇总
Greenplum数据库故障分析——semop(id=2000421076,num=11) failed: invalid argument
GUI+SQLServer考试系统
Calculate the sum of the main diagonals of the array
牛客编程题--必刷101之动态规划(一文彻底了解动态规划)
How to separate jar packages and resource files according to packaging?
Notes on key review of software engineering at the end of the term
Learn about common functional interfaces
[207] several possible causes of Apache crash
TCP congestion control details | 1 summary
108. simple chat room 11: realize client group chat
Discover K8E: minimalist kubernetes distribution
Leetcode 1169. 查询无效交易(如果数据量不大,这种题还是得暴力枚举解决)
Pybullet robot simulation environment construction 5 Robot pose visualization
pybullet机器人仿真环境搭建 5.机器人位姿可视化
【毕业季】致毕业生的一句话:天高任鸟飞,海阔凭鱼跃
100+ data science interview questions and answers Summary - basic knowledge and data analysis
What is the preferential account opening policy of securities companies now? Is it safe to open an account online now?
In a bad mood, I just write code like this
进军AR领域,这一次罗永浩能成吗?








