当前位置:网站首页>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;
}
};
边栏推荐
- Scala Basics (II): variables and data types
- [机缘参悟-31]:鬼谷子-抵巇[xī]篇-危机是危险与机会并存
- Web3去中心化存储生态图景
- Use the array to calculate the average of N numbers, and output the numbers greater than the average
- TCP congestion control details | 1 summary
- Redis migration (recommended operation process)
- Calculate the average of N numbers in the index group of X, and return the number that is less than the average and closest to the average through formal parameters
- 5g is not flat and 6G is restarted. China leads wireless communication. What is the biggest advantage of 6G?
- 电路中缓存的几种形式
- Stm32h7b0 replaces the h750 program, causing the MCU to hang up and unable to burn the program
猜你喜欢

探讨:下一代稳定币

20:第三章:开发通行证服务:3:在程序中,打通redis服务器;(仅仅是打通redis服务器,不涉及具体的业务开发)

Learn about common functional interfaces
Scala Basics (II): variables and data types

TCP congestion control details | 1 summary

牛客编程题--必刷101之动态规划(一文彻底了解动态规划)

当一个程序员一天被打扰 10 次,后果很惊人!

Teach you to learn dapr - 2 Must know concept
Redis Guide (8): principle and implementation of Qianfan Jingfa distributed lock

r329(MAIX-II-A(M2A)资料汇总
随机推荐
Junit单元测试
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!
[chat in 5] eight years after graduation, I have been pursuing my dream
Learn about common functional interfaces
Redis overview
The student record consists of student number and academic performance. The data of n students have been stored in the a structure array to find out the student record with the lowest performance
Interpretation of cloud native microservice technology trend
Kubecon China 2021 Alibaba cloud special session is coming! These first day highlights should not be missed
Some instance methods of mono
Day10 daily 3 questions (1): sum gradually to get the minimum value of positive numbers
Scala 基础 (二):变量和数据类型
Greenplum数据库故障分析——semop(id=2000421076,num=11) failed: invalid argument
探讨:下一代稳定币
[Blue Bridge Cup training 100 questions] scratch distinguishing prime numbers and composite numbers Blue Bridge Cup scratch competition special prediction programming question intensive training simul
GUI+SQLServer考试系统
Teach you to learn dapr - 2 Must know concept
QT 5.9.8 installation tutorial
【从删库到跑路】JDBC 完结篇(一天学完系列!!学完赶紧跑!)
C language --- basic function realization of push box 01
Set up your own website (16)