当前位置:网站首页>[leetcode weekly race record] record of the 79th biweekly race + the 295th weekly race
[leetcode weekly race record] record of the 79th biweekly race + the 295th weekly race
2022-06-09 13:25:00 【One, two, three o-0-o】
【leetcode Weekly record 】 The first 79 A fortnight game + The first 295 Weekly game records
Personal ranking after the game
Game analysis summary
The first 79 A fortnight game
6083. Determine whether the number count of a number is equal to the value of the digit
class Solution {
public:
bool digitCount(string num) {
unordered_map<int,int> unMap;
for(char c : num) unMap[c - '0']++;
int n = num.size();
for(int i{
};i<n;++i){
if(unMap[i] == (num[i] - '0')){
continue;
}else return false;
}
return true;
}
};
6084. The sender with the maximum number of words
class Solution {
public:
// Simulation solution
string largestWordCount(vector<string>& messages, vector<string>& senders) {
int n = messages.size();
unordered_map<string,int> unMap;
for(int i{
};i<n;++i){
// Get the number of words
vector<string> res;
string result;
stringstream input(messages[i]);
while(input>>result)
res.push_back(result);
unMap[senders[i]] += res.size();
}
vector<pair<int,string>> vv;
for(auto [key,value] : unMap){
vv.push_back({
value,key});
}
sort(vv.begin(),vv.end(),[](auto &&a,auto &&b){
if(a.first == b.first){
return a.second < b.second;
}
return a.first < b.first;
});
string result = vv[vv.size()-1].second;
return result;
}
};
6085. The greatest overall importance of the road
// greedy : Greedy for the degree of each point , Then the point with the most degrees must be assigned a larger weight and better
class Solution {
public:
long long maximumImportance(int n, vector<vector<int>>& roads) {
// Count the degree of each point
vector<int> node(n,0);
for(auto &v : roads){
node[v[0]]++;
node[v[1]]++;
}
sort(node.begin(),node.end());
// The point with the largest degree assigns the largest weight
long long result{
};
for(int i{
};i<n;++i){
result += 1LL * node[i] * (i+1);
}
return result;
}
};
10011. Book tickets for the concert in groups
Ignore
The first 295 Weekly match
2287. Rearrange the characters to form the target string
class Solution {
public:
int rearrangeCharacters(string s, string target) {
unordered_map<int,int> unMap;
for(char c : target) unMap[c-'a']++;
int result{
INT_MAX};
vector<int> need(26);
for(char c : s){
if(unMap[c-'a'] > 0)
need[c-'a']++;
}
for(auto [key,value] : unMap){
if(value > 0){
if(need[key] <= 0) return 0;
}
}
for(int i{
};i<26;++i){
if(need[i] > 0 && unMap[i] > 0){
result = min(need[i]/unMap[i],result);
}
}
return result;
}
};
2288. Price reduction
// Personal version
class Solution {
public:
bool isLeagal(string &s){
if(s == "$") return false;
int n = s.size();
for(int i{
};i<n;++i){
if(s[0] != '$') return false;
if(i > 0 ){
if(( s[i] >= '0' && s[i] <= '9')){
}else return false;
}
}
return true;
}
string discountPrices(string sentence, int discount) {
// Get the number of words
vector<string> res;
string result;
stringstream input(sentence);
while(input>>result)
res.push_back(result);
int n = res.size();
for(int i{
};i<n;++i){
string s = res[i];
if(isLeagal(s)){
double prices = stod(s.substr(1,s.size()-1));
prices *= (100-discount) * 0.01;
ostringstream oss;
oss << fixed << setprecision(2) << prices;
string ans1 = "$";
ans1+=oss.str();
res[i] = ans1;
}
}
string aa;
for(int i{
};i<n;++i){
aa += res[i];
if(i != n-1) aa+=" ";
}
return aa;
}
};
// Easy version
class Solution {
public:
string discountPrices(string sentence, int discount) {
string res;
istringstream iss(sentence);
string t;
// c++ Standard library functions getline
while (getline(iss, t, ' ')) {
// while (iss >> t)
bool isPrice = (t.size() > 1 && t[0] == '$');
// Check whether it is a price word
if (isPrice) {
for (int i = 1; i < t.size(); ++i) {
if (t[i] == '$' || t[i] < '0' || t[i] > '9') {
isPrice = 0; break;
}
}
}
if (isPrice) {
string p = t.substr(1);
double price = stod(p);
price *= (100 - discount) * 0.01;
// Only two decimal places are truncated
ostringstream oss;
// setprecision Control the number after the decimal point
oss << fixed << setprecision(2) << price;
res += '$' + oss.str() + ' ';
} else {
res += t + ' ';
}
}
res.pop_back();
return res;
}
};
2289. Make the array in non decreasing order
// Application of monotone stack
// According to the meaning of the question, it can be transformed into : Converted to the maximum value of the time when all elements are deleted
class Solution {
public:
int totalSteps(vector<int> &nums) {
int ans = 0;
// Monotonically decreasing stack stores elements and their deletion time
stack<pair<int, int>> st;
for (int num : nums) {
int maxT = 0;
// Get it to delete num And delete num Between all numbers less than num The maximum moment of the value of
while (!st.empty() && st.top().first <= num) {
maxT = max(maxT, st.top().second);
st.pop();
}
maxT = st.empty() ? 0 : maxT + 1;
ans = max(ans, maxT);
st.emplace(num, maxT);
}
return ans;
}
};
2290. The minimum number of obstacles that need to be removed to reach the corner
Question 4 will not be considered for the time being
Reflection summary
Personal situation
The first 29、30 sub-participation leetcode competition ;
In total, I got 5 Time 12 branch ,15 Time 7 branch ,10 Time 3 branch ;
Follow up improvement
- greedy + Special review of graph theory 、 Training and summary system training , summary
- Special review of monotonous stack 、 Training and summary system training , summary
边栏推荐
- Loki: like Prometheus, but for logs
- Navicat instructions
- Handlebars. JS template engine usage I
- [description of promtail configuration file]
- 数据库day-4
- C language -- linear list -- double linked list
- [C language practice - Young's matrix]
- Yunna intelligent operation and maintenance management system platform, visual operation and maintenance system management
- Tree diameter (supplement: another DP)
- Zhoubolei annual progress overview of model interpretability 20200805
猜你喜欢

Idea merges the newly added modifications to the previous version

DDD建模方法论之【事件风暴法】

【C语言练习——打印整数二进制的奇数位和偶数位】

云呐|行政单位固定资产管理制度,单位固定资产管理办法

How to solve the worry of enterprise network with the acceleration of cloud network integration on the third anniversary of 5g licensing?

周博磊《模型可解释性年度进展概述》20200805

【C语言练习——打印正方形及其变形】

Record the troubleshooting of high program memory consumption

Execution engine of JVM family
![[C language practice - printing diamond and its deformation]](/img/ea/02c6ae5d178d47fe04b3550829f1bd.png)
[C language practice - printing diamond and its deformation]
随机推荐
[idea imports gradle project and starts]
How can PostgreSQL in k8s export query results and import them to the database on the local windows machine
IDEA将现在新增加的修改合并cherry pick到之前的版本
浅析网络可视化分析技术
Yunna intelligent operation and maintenance management system platform, visual operation and maintenance system management
【C语言练习——合并两个有序序列】
机器学习-学习笔记(二) --&gt; 模型评估与选择
Zhoubolei annual progress overview of model interpretability 20200805
云呐|资产管理系统有哪些类型,分为哪几方面
[noip2015 improvement group] transportation plan
云呐|服务器监控的重要性,监控管理服务器有什么作用
Machine learning - learning notes (II) - & gt; Model evaluation and selection
手把手教你用js实现一个虚拟机
Notes - round square tree
Analysis on the resumption of the most serious downtime in the history of Facebook on October 4, 2021
[Loki introduction, deployment, use]
U8g2图形库与STM32移植(I2C,软件与硬件)
Comment résoudre le problème du réseau d'entreprise en accélérant la fusion du réseau Cloud pour le troisième anniversaire de la licence 5G?
C语言中的数组、字符串、函数、结构体
Tree diameter (supplement: another DP)
