随笔分类 - 算法
摘要:
题目链接:2454.下一个更大元素IV 题目: 给你一个下标从 0 开始的非负整数数组 nums 。对于 nums 中每一个整数,你必须找到对应元素的 第二大 整数。 如果 nums[j] 满足以下条件,那么我们称它为 nums[i] 的 第二大 整数: j > i nums[j] > nums[i
阅读全文
题目链接:2454.下一个更大元素IV 题目: 给你一个下标从 0 开始的非负整数数组 nums 。对于 nums 中每一个整数,你必须找到对应元素的 第二大 整数。 如果 nums[j] 满足以下条件,那么我们称它为 nums[i] 的 第二大 整数: j > i nums[j] > nums[i
阅读全文
摘要:
#1 不同的平均值数目 不同的平均值数目 ##Solution class Solution { public: int distinctAverages(vector<int>& nums) { sort(nums.begin(),nums.end()); int i = 0,j = nums.s
阅读全文
#1 不同的平均值数目 不同的平均值数目 ##Solution class Solution { public: int distinctAverages(vector<int>& nums) { sort(nums.begin(),nums.end()); int i = 0,j = nums.s
阅读全文
摘要:
1 温度转换 温度转换 Solution class Solution { public: vector<double> convertTemperature(double celsius) { double kelvin = celsius + 273.15; double fahrenheit
阅读全文
1 温度转换 温度转换 Solution class Solution { public: vector<double> convertTemperature(double celsius) { double kelvin = celsius + 273.15; double fahrenheit
阅读全文
摘要:
1 作用 置换环是用来求解数组排序元素间所需最小交换次数这类问题。 置换环思想:置换环将每个元素指向其排序后应在的位置,最终首位相连形成一个环**(若数字在最终位置,则其自身成环)**,可知元素之间的交换只会在同一个环内进行,而每个环内的最小交换次数为 $$ 环上元素数量 - 1 $$ 图例: 图中
阅读全文
1 作用 置换环是用来求解数组排序元素间所需最小交换次数这类问题。 置换环思想:置换环将每个元素指向其排序后应在的位置,最终首位相连形成一个环**(若数字在最终位置,则其自身成环)**,可知元素之间的交换只会在同一个环内进行,而每个环内的最小交换次数为 $$ 环上元素数量 - 1 $$ 图例: 图中
阅读全文
摘要:
#1.数组中不等三元组的数目 数组中不等三元组的数目 ##Solution class Solution { public: int unequalTriplets(vector<int>& nums) { int n = nums.size(); int cnt = 0; for(int i =
阅读全文
#1.数组中不等三元组的数目 数组中不等三元组的数目 ##Solution class Solution { public: int unequalTriplets(vector<int>& nums) { int n = nums.size(); int cnt = 0; for(int i =
阅读全文
摘要:
#1.根据规则将箱子分类 根据规则将箱子分类 ##Solution class Solution { public: string categorizeBox(int length, int width, int height, int mass) { long long w = 1e4, v =
阅读全文
#1.根据规则将箱子分类 根据规则将箱子分类 ##Solution class Solution { public: string categorizeBox(int length, int width, int height, int mass) { long long w = 1e4, v =
阅读全文
摘要:
#1.分割圆的最少切割次数 分割圆的最少切割次数 ##Solution class Solution { public: int numberOfCuts(int n) { int tmp = 360 / n; if(n == 1) return 0; if(n % 2 == 0) return n
阅读全文
#1.分割圆的最少切割次数 分割圆的最少切割次数 ##Solution class Solution { public: int numberOfCuts(int n) { int tmp = 360 / n; if(n == 1) return 0; if(n % 2 == 0) return n
阅读全文
摘要:
#1.找出中枢整数 找出中枢整数 Solution class Solution { public: int pivotInteger(int n) { int sum = (1 + n)* n / 2; int tmp = (int)sqrt(sum); return tmp * tmp == s
阅读全文
#1.找出中枢整数 找出中枢整数 Solution class Solution { public: int pivotInteger(int n) { int sum = (1 + n)* n / 2; int tmp = (int)sqrt(sum); return tmp * tmp == s
阅读全文
摘要:
#1.回环句 回环句 Solution class Solution { public: bool isCircularSentence(string sentence) { int n = sentence.size(), i = 0; if (sentence[0] != sentence[n
阅读全文
#1.回环句 回环句 Solution class Solution { public: bool isCircularSentence(string sentence) { int n = sentence.size(), i = 0; if (sentence[0] != sentence[n
阅读全文
摘要:
#1.数组中字符串的最大值 数组中字符串的最大值 Solution class Solution { public: int maximumValue(vector<string>& strs) { int ans = -1; for(auto x : strs){ int n = x.size()
阅读全文
#1.数组中字符串的最大值 数组中字符串的最大值 Solution class Solution { public: int maximumValue(vector<string>& strs) { int ans = -1; for(auto x : strs){ int n = x.size()
阅读全文
摘要:
#1.统计相似字符串对的数目 统计相似字符串对的数目 Solution class Solution { public: int similarPairs(vector<string>& words) { unordered_map<int,int> book; int len1 = words.s
阅读全文
#1.统计相似字符串对的数目 统计相似字符串对的数目 Solution class Solution { public: int similarPairs(vector<string>& words) { unordered_map<int,int> book; int len1 = words.s
阅读全文
摘要:
1.统计能整除数字的位数 统计能整除数字的位数 Solution class Solution { public: int countDigits(int num) { int ans = 0; int n = num; while(n){ int t = n % 10; if(num % t ==
阅读全文
1.统计能整除数字的位数 统计能整除数字的位数 Solution class Solution { public: int countDigits(int num) { int ans = 0; int n = num; while(n){ int t = n % 10; if(num % t ==
阅读全文
摘要:
A - Power Given integers A and B, print the value A^B. 基础不解答 B - First Query Problem 基础不解答 C - Cash Register Takahashi is a cashier. There is a cash r
阅读全文
A - Power Given integers A and B, print the value A^B. 基础不解答 B - First Query Problem 基础不解答 C - Cash Register Takahashi is a cashier. There is a cash r
阅读全文
摘要:
1.最多可以摧毁的敌人城堡数目 题目 最多可以摧毁的敌人城堡数目 Solution 可以第一重循环找到$1$,然后从该位置分别向左和向又寻找$-1$,寻找过程中遇到$1$则停止,不更新ans,遇到$-1$则更新ans。 class Solution { public: int captureFort
阅读全文
1.最多可以摧毁的敌人城堡数目 题目 最多可以摧毁的敌人城堡数目 Solution 可以第一重循环找到$1$,然后从该位置分别向左和向又寻找$-1$,寻找过程中遇到$1$则停止,不更新ans,遇到$-1$则更新ans。 class Solution { public: int captureFort
阅读全文
摘要:
1.到目标字符串的最短距离 题目 Solution class Solution { public: int closetTarget(vector<string>& words, string target, int startIndex) { int n = words.size(); int
阅读全文
1.到目标字符串的最短距离 题目 Solution class Solution { public: int closetTarget(vector<string>& words, string target, int startIndex) { int n = words.size(); int
阅读全文

浙公网安备 33010602011771号