684. 冗余连接 发表于 2021-01-13 更新于 2025-02-26 分类于 algorithm-practice , leetcode 本文字数: 123 阅读时长 ≈ 1 分钟#思路有环无向图中找出环上最后出现的边
1203. 项目管理 发表于 2021-01-12 更新于 2025-02-26 分类于 algorithm-practice , leetcode 本文字数: 73 阅读时长 ≈ 1 分钟双重拓扑排序: 组内 & 组间拓扑排序
1151. LCA in a Binary Tree 发表于 2021-01-12 更新于 2025-02-26 分类于 algorithm-practice , PTA 本文字数: 305 阅读时长 ≈ 1 分钟二叉树上寻找最近公共祖先需要注意节点的key不一定连续
1036. Boys vs Girls 发表于 2021-01-11 更新于 2025-02-26 分类于 algorithm-practice , PTA 本文字数: 100 阅读时长 ≈ 1 分钟送分题123456789101112131415161718192021222324252627282930313233343536373839404142434445464748#include <iostream>using namespace std;struct student { string name; string major;};int main(){ int n; cin >> n; student s, male_min, female_max; int score, male_score_min = 101, female_score_max = -1; string gender; for (int i = 0; i < n; i++) { cin >> s.name >> gender >> s.major >> score; if (gender == "M") { if (score < male_score_min) { male_min = s; male_score_min = score; } } else { if (score > female_score_max) { female_max = s; female_score_max = score; } } } if (female_score_max != -1) { cout << female_max.name << " " << female_max.major << endl; } else { cout << "Absent" << endl; } if (male_score_min != 101) { cout << male_min.name << " " << male_min.major << endl; } else { cout << "Absent" << endl; } if (female_score_max != -1 && male_score_min != 101) { cout << female_score_max - male_score_min << endl; } else { cout << "NA" << endl; } return 0;}
1202. 交换字符串中的元素 发表于 2021-01-11 更新于 2025-02-26 分类于 algorithm-practice , leetcode 本文字数: 243 阅读时长 ≈ 1 分钟#题意给定一些可以任意交换位置的组, 求整个字符串的最小字典序
1093. Count PAT's 发表于 2021-01-10 更新于 2025-02-26 分类于 algorithm-practice , PTA 本文字数: 128 阅读时长 ≈ 1 分钟#题意计算PAT字串个数
1140. Look-and-say Sequence 发表于 2021-01-10 更新于 2025-02-26 分类于 algorithm-practice , PTA 本文字数: 95 阅读时长 ≈ 1 分钟#题意求一个数字用行程编码压缩n-1次的结果
228. 汇总区间 发表于 2021-01-10 更新于 2025-02-26 分类于 algorithm-practice , leetcode 本文字数: 71 阅读时长 ≈ 1 分钟水题, 注意边界情况12345678910111213141516171819class Solution {public: vector<string> summaryRanges(vector<int>& nums) { int n = nums.size(); int last = (n>0?nums[0]:0); vector<string> res; for(int i=1;i<=n;i++){ if(i==n || nums[i]!=nums[i-1]+1){ if (last==nums[i-1]){ res.push_back(to_string(last)); }else{ res.push_back(to_string(last)+"->"+to_string(nums[i-1])); } if(i<n) last=nums[i]; } } return res; }};
每日小结 发表于 2021-01-10 更新于 2025-02-26 分类于 daily , 2021 本文字数: 84 阅读时长 ≈ 1 分钟#模运算的性质(程序设计版)模运算与基本四则运算有些相似,但是除法例外。其规则如下: