我的不会的题目以及会的题目的改进基本都来自这位up的讲解视频
题目🔗:https://leetcode-cn.com/contest/weekly-contest-167/
题目🔗:https://leetcode-cn.com/contest/weekly-contest-168/
题目🔗:https://leetcode-cn.com/contest/weekly-contest-170/
题目🔗:https://leetcode-cn.com/contest/weekly-contest-171/
题目🔗:https://leetcode-cn.com/contest/weekly-contest-172/
题目🔗:https://leetcode-cn.com/contest/weekly-contest-173/
题目🔗:https://leetcode-cn.com/contest/weekly-contest-174/
题目🔗:https://leetcode-cn.com/contest/weekly-contest-175/
题目🔗:https://leetcode-cn.com/contest/weekly-contest-176/
题目🔗:https://leetcode-cn.com/contest/weekly-contest-177/
题目🔗:https://leetcode-cn.com/contest/weekly-contest-178/
题目🔗:https://leetcode-cn.com/contest/weekly-contest-179/
题目🔗:https://leetcode-cn.com/contest/weekly-contest-180/
题目🔗:https://leetcode-cn.com/contest/weekly-contest-181/
题目🔗:https://leetcode-cn.com/contest/weekly-contest-181/
题目🔗:https://leetcode-cn.com/contest/biweekly-contest-19/
题目🔗:https://leetcode-cn.com/contest/biweekly-contest-20/
题目🔗:https://leetcode-cn.com/contest/biweekly-contest-21/
题目🔗:https://leetcode-cn.com/contest/biweekly-contest-22/
void dfs()//参数用来表示状态
{
if(到达终点状态)
{
...//根据题意添加
return;
}
if(越界或者是不合法状态)
return;
if(特殊状态)//剪枝
return ;
for(扩展方式)
{
if(扩展方式所达到状态合法)
{
修改操作;//根据题意来添加
标记;
dfs();
(还原标记);
//是否还原标记根据题意
//如果加上(还原标记)就是 回溯法
}
}
}
- vector< vector> tmp(10, vector(10,0));
while(!Q.empty()){
TreeNode* tmp = Q.front(); Q.pop();
tt.push_back(tmp->val);
if(tmp->left != NULL) Q.push(tmp->left), nextCount++;
if(tmp->right != NULL) Q.push(tmp->right), nextCount++;
cur++;
if(cur == Count){
buf.push_back(tt);
tt.clear();
cur = 0;
Count = nextCount;
nextCount = 0;
}
}
- sscanf(date.c_str(), "%d-%d-%d", &year, &month, &day); 格式化读取年月日
- scanf 从控制台输入 fscanf 从文件输入 sscanf 从指定字符串输入
- #define is_year(x) (x % 400 == 0) || (x % 4 ==0 && x % 100 !=0) ? 1 : 0
sscanf(date.c_str(), "%d-%d-%d", &year, &month, &day);
int month_length[] = {31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30};
int ans = 0;
while (year != 1971 or month != 1 or day != 1) {
++ans;
if (--day == 0)
if (--month == 0)
--year;
if (day == 0) {
day = month_length[month];
if (month == 2 && leap_year(year))
++day;
}
if (month == 0)
month = 12;
}
如果是子串拼接成原串问题,那么就把两个原串拼在一起(str1 + str2 | str2 + str1),子串能拼出两个原串拼接在一起的话就能拼出两个原串(if (str1+str2!=str2+str1) return "";)
//{{1,2,3},{1,2,4},{1,2,5},{1,2,6},{1,2,7},{1,2,8}} 会按照每一行的第一个值排序,第一个值相同再比较第二个值,和vector<pair<>>的道理是一样的
//vector 从大到小排序 sort(tmp.begin(), tmp.end(), greater<vector<int>>()) || sort(tmp.rbegin(),tmp.rend())
// 乘方函数 pow(x,y) x^y