当前位置:网站首页>Leetcode 1170. 比较字符串最小字母出现频次(可以,已解决)
Leetcode 1170. 比较字符串最小字母出现频次(可以,已解决)
2022-06-26 16:36:00 【我不是萧海哇~~~~】

定义一个函数 f(s),统计 s 中(按字典序比较)最小字母的出现频次 ,其中 s 是一个非空字符串。
例如,若 s = “dcce”,那么 f(s) = 2,因为字典序最小字母是 “c”,它出现了 2 次。
现在,给你两个字符串数组待查表 queries 和词汇表 words 。对于每次查询 queries[i] ,需统计 words 中满足 f(queries[i]) < f(W) 的 词的数目 ,W 表示词汇表 words 中的每个词。
请你返回一个整数数组 answer 作为答案,其中每个 answer[i] 是第 i 次查询的结果。
示例 1:
输入:queries = ["cbd"], words = ["zaaaz"]
输出:[1]
解释:查询 f("cbd") = 1,而 f("zaaaz") = 3 所以 f("cbd") < f("zaaaz")。
示例 2:
输入:queries = ["bbb","cc"], words = ["a","aa","aaa","aaaa"]
输出:[1,2]
解释:第一个查询 f("bbb") < f("aaaa"),第二个查询 f("aaa") 和 f("aaaa") 都 > f("cc")。
提示:
- 1 <= queries.length <= 2000
- 1 <= words.length <= 2000
- 1 <= queries[i].length, words[i].length <= 10
- queries[i][j]、words[i][j] 都由小写英文字母组成
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;
}
};
边栏推荐
- STM32F103C8T6实现呼吸灯代码
- R language generalized linear model function GLM, GLM function to build logistic regression model, analyze whether the model is over discrete, and use the ratio of residual deviation and residual degr
- Scala 基礎 (二):變量和數據類型
- Redis order sorting command
- 安信证券排名第几位?开户安全吗?
- pybullet机器人仿真环境搭建 5.机器人位姿可视化
- Arduino UNO + DS1302简单获取时间并串口打印
- Scala 基础 (二):变量和数据类型
- 若依微服务特殊字符串被过滤的解决办法
- MS|谢黎炜组发现混合益生菌制剂及其代谢产物可缓解结肠炎
猜你喜欢
Scala 基礎 (二):變量和數據類型

This year, the AI score of college entrance examination English is 134. The research of Fudan Wuda alumni is interesting

用Attention和微调BERT进行自然语言推断-PyTorch

# 补齐短板-开源IM项目OpenIM关于初始化/登录/好友接口文档介绍

Vibrating liquid quantity detecting device

长安链交易防重之布谷鸟过滤器

5g is not flat and 6G is restarted. China leads wireless communication. What is the biggest advantage of 6G?

【力扣刷题】11.盛最多水的容器//42.接雨水

MS | Xie Liwei group found that mixed probiotics and their metabolites could alleviate colitis

C语言所有知识点小结
随机推荐
day10每日3题(2):统计最大组的数目
长安链交易防重之布谷鸟过滤器
JS教程之 使用 Electron.JS 构建原生桌面应用程序乒乓游戏
【蓝桥杯集训100题】scratch辨别质数合数 蓝桥杯scratch比赛专项预测编程题 集训模拟练习题第15题
R329 (maix-ii-a (M2A) data summary
Codeforces Round #802 (Div. 2)
mha 切换(操作流程建议)
The details of the first pig heart transplantation were fully disclosed: human herpes virus was found in the patient, the weight of the heart doubled after death, and myocardial cell fibrosis
Niuke programming problem -- dynamic programming of must brush 101 (a thorough understanding of dynamic programming)
Lifeifei's team applied vit to the robot, increased the maximum speed of planning reasoning by 512 times, and also cued hekaiming's Mae
MS | Xie Liwei group found that mixed probiotics and their metabolites could alleviate colitis
# 补齐短板-开源IM项目OpenIM关于初始化/登录/好友接口文档介绍
JS教程之Electron.js设计强大的多平台桌面应用程序的好工具
【从删库到跑路】MySQL基础 完结篇(入个门先跑路了。。)
How to implement interface current limiting?
JS tutorial using electron JS build native desktop application ping pong game
Structure the graduation project of actual combat camp
proxy
Scala Basics (II): variables and data types
Binary array command of redis