当前位置:网站首页>Solution to the problem of the 80th fortnight competition of leetcode
Solution to the problem of the 80th fortnight competition of leetcode
2022-06-12 05:57:00 【Vain957】
A& 6095. Strong password verifier II
Simple simulation :
class Solution {
public:
bool strongPasswordCheckerII(string pd) {
unordered_map<char,bool>vis;
string a="[email protected]#$%^&*()-+";
for(int i=0;i<a.size();i++){
vis[a[i]]=true;
}
int jp=0;
int n=pd.size();
if(n<8){
return false;
}
for(int i=0;i+1<n;i++){
if(pd[i]==pd[i+1]){
return false;
}
}
for(int i=0;i<n;i++){
if(pd[i]>='a'&&pd[i]<='z'){
jp++;
break;
}
}
for(int i=0;i<n;i++){
if(pd[i]>='0'&&pd[i]<='9'){
jp++;
break;
}
}
for(int i=0;i<n;i++){
if(pd[i]>='A'&&pd[i]<='Z'){
jp++;
break;
}
}
for(int i=0;i<n;i++){
if(vis[pd[i]]){
jp++;
break;
}
}
return jp==4;
}
};
B& 6096. The number of successful spells and potions
Sort bisection
class Solution {
public:
static bool cmp(pair<int,int>&a,pair<int,int>&b){
return a.first<b.first;
}
vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) {
vector<pair<int,int>>pir;
for(int i=0;i<spells.size();i++){
pir.push_back(make_pair(spells[i],i));
}
sort(pir.begin(),pir.end(),cmp);
sort(potions.begin(),potions.end());
vector<int>ans(pir.size(),0);
int n=potions.size();
for(int i=0;i<pir.size();i++){
long long aim=(success%pir[i].first!=0)+success/pir[i].first; int sum=aim>(long long)INT_MAX?0:(n-(lower_bound(potions.begin(),potions.end(),aim)-potions.begin()));
ans[pir[i].second]=sum;
}
return ans;
}
};
C& 6097. Match after replacing characters
Violent simulation
There is something wrong with the Chinese title
class Solution {
public:
bool matchReplacement(string s, string sub, vector<vector<char>>& mappings) {
unordered_map<char,vector<char>>mp;
for(int i=0;i<mappings.size();i++){
mp[mappings[i][0]].push_back(mappings[i][1]);
}
for(int i=0;i+sub.size()-1<s.size();i++){
bool t=true;
for(int j=0;j<sub.size();j++){
if(s[i+j]!=sub[j]){
auto it =find(mp[sub[j]].begin(),mp[sub[j]].end(),s[i+j]);
if(it==mp[sub[j]].end()){
t=false;
break;
}
}
}
if(t){
return true;
}
}
return false;
}
};
D& 6098. The statistical score is less than K Number of subarrays of
Mathematical calculation
class Solution {
public:
long long countSubarrays(vector<int>& nums, long long k) {
long long sum=0,l=0,ans=0;
for(int i=0;i<nums.size();i++){
sum+=nums[i];
long long t=sum*(i-l+1);
while(t>=k&&l<=i){
sum-=nums[l];
l++;
t=sum*(i-l+1);
}
ans+=i-l+1;
}
return ans;
}
};
边栏推荐
- Makefile文件编写快速掌握
- flex/fixed上中下(移動端)
- Chapter 8 - structure
- Nrf52832 services et fonctionnalités personnalisés
- RTMP streaming +rtmp playback low delay solution in unity environment
- China embolic coil market trend report, technical innovation and market forecast
- log4j 1. X upgrade to 2 Solution of X dependency incompatibility
- About architecture (in no particular order)
- nrf52832--官方例程ble_app_uart添加led特性,实现电脑uart和手机app控制开发板led开和关
- jpg格式与xml格式文件分离到不同的文件夹
猜你喜欢

Un mois de DDD hépatique.

E-book analysis

Login authentication filter

前台展示LED数字(计算器上数字类型)

Introduction to redis high availability

Identification of campus green plants based on tensorflow

Chapter 8 - structure

Unable to access this account. You may need to update your password or grant the account permission to synchronize to this device. Tencent corporate email
![User login [next]](/img/e1/c3429f0b2bf06e3f7d87e32ca153b6.jpg)
User login [next]

Introduction to thread pool: ThreadPoolExecutor
随机推荐
nrf52832--官方例程ble_app_uart添加led特性,实现电脑uart和手机app控制开发板led开和关
Annotation configuration of filter
GRP development: four communication modes of GRP
项目开发流程简单介绍
Select gb28181, RTSP or RTMP for data push?
Quickly master makefile file writing
Unable to access this account. You may need to update your password or grant the account permission to synchronize to this device. Tencent corporate email
Un mois de DDD hépatique.
Jackson - how to convert the array string with only one map object to list < map >
Special materials | household appliances, white electricity, kitchen electricity
Research Report on market supply and demand and strategy of China's digital camera lens industry
Flex / fixed Upper, Middle and Lower (Mobile end)
Project management and overall planning
E-book analysis
Laravel8 authentication login
Understanding of distributed transactions
Nrf52832 services et fonctionnalités personnalisés
Halcon 3D 深度图转换为3D图像
项目管理与统筹
Lock and reentrankload