当前位置:网站首页>Une explication du 80e match bihebdomadaire de leetcode
Une explication du 80e match bihebdomadaire de leetcode
2022-06-12 05:57:00 【Vain957】
A& 6095. Détecteur de mot de passe fort II
Simulation simple:
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. Le nombre de sorts et de potions réussis
Trier deux points
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. Correspondance après remplacement des caractères
Simulation de violence
Il y a un problème avec le titre chinois
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. Score statistique inférieur à K Nombre de sous - tableaux pour
Calcul mathématique
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;
}
};
边栏推荐
猜你喜欢

How to split a row of data into multiple rows in Informix database

Conversion of Halcon 3D depth map to 3D image

Halcon 3D 1 Reading 3D data

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

Halcon 用点来拟合平面

Beginning is an excellent emlog theme v3.1, which supports emlog Pro

User login (medium)
![[untitled]](/img/75/599c5b13dd483fad50f73ddb431989.jpg)
[untitled]

Word frequency statistics using Jieba database

为什么联合索引是最左匹配原则?
随机推荐
Introduction to redis high availability
Json-c common APIs
Liunx Foundation
Automatic annotation of target detection based on lffd model to generate XML file
About architecture (in no particular order)
为什么数据库不使用二叉树、红黑树、B树、Hash表? 而是使用了B+树
数据库实验二:数据更新
Divide a folder image into training set and test set
Leetcode dynamic programming
[machine learning] first day of introduction
Individual application for ov type SSL certificate
User login [next]
Mysql笔记
BlockingQueue interface introduction
Glossary of Chinese and English terms for pressure sensors
Nrf52832 -- official routine ble_ app_ UART adds the LED feature to enable the computer UART and mobile app to control the LED on and off of the development board
Jpg format and XML format files are separated into different folders
The relation between virtual function and pure virtual function
User login 【 I 】
Leetcode-1663. Minimum string with given value