摘要:
简单模拟,最小的两个数字是a, b, 最大的数字时a + b + c #include<iostream> #include<cstdio> #include<algorithm> #include<set> using namespace std; int main() { multiset<in 阅读全文
摘要:
思路:动态规划 首先计算原数组的条件数组,及所有的元素都%2 f[i]表示从零到i中选,且以第i项为结尾的最长奇偶子数组。 class Solution { public: int longestAlternatingSubarray(vector<int>& nums, int threshold 阅读全文
摘要:
找规律的小题目 c ++ class Solution { public: int theMaximumAchievableX(int num, int t) { return num + t * 2; } }; 思路,动态规划。 f[i]表示,所有从0 - i - 1中跳到点 i 的方式的执行操作 阅读全文
摘要:
方法1:利用桶的思想同时匹配所有words中的子串 (走路写法) 把所有首字母相同的子串放入到一个桶中,然后遍历s,对于首字母为s[i]的单词,若其大小为1则res ++, 否则删掉s[i],并根据s[i + 1]放入新的桶中。 c ++ class Solution { public: int n 阅读全文
摘要:
利用动态规划的思想,把每个格子上下左右连续的1的个数算出来,再从头到尾遍历一遍即可获得答案。 c ++ class Solution { public: int orderOfLargestPlusSign(int n, vector<vector<int>>& mines) { vector<ve 阅读全文
摘要:
深度优先遍历判断二分图 c ++ class Solution { const static int N = 110, M = N * N; int h[N], e[M], ne[M], idx; int st[N]; void add(int a, int b) { e[idx] = b, ne[ 阅读全文
摘要:
首先c一手暴力法:利用树状数组,线段树,归并排序法查找逆序对,即全局倒置;在求出局部倒置,时间复杂度为nlogn 这里为了好写,采用树状数组方法进行逆序对求解 注:树状数组中下标不能有0,要对原数组进行+1修正 c ++ class Solution { int n; int tr[1000010] 阅读全文