算法题常见的BUG错误(总结)
2024-09-05 20:27:28
1. 快排的partition
if(l >= r)
return ;
int i = l, j = r;
int tmp = v[i];
while(i < j) {
while(i < j && v[j] >= tmp) j--;
while(i < j && v[i] <= tmp) i++;
if(i < j) swap(v[i], v[j]);
}
swap(v[l], v[i]);
2. pq的排序规则
pop正好是和比较是反着的
struct cmp{
bool operator ()(const pair<int,pair<int,int>> &a, const pair<int,pair<int,int>> &b) {
return a.first > b.first;
}
};
3. kmp的next数组
next[0] = -1;
for(int i=1; i<len; i++) {
int j = next[i-1];
while(j != -1 && s[j+1] != s[i])
j = next[j];
if(s[j+1] == s[i])
next[i] = j+1;
else
next[i] = -1;
}
最新文章
- Python之路-(Django(Cookie、分页))
- Scala编程--基本类型和操作
- Bootstrap页面布局23 - BS折叠内容
- x^y=(x&;~y)|(~x&;y)证明
- UVaLive 6608 Cabin Baggage (水题)
- Visual Studio&#174; 2010 Web Deployment Projects站点编译生成bin同时发表插件
- 基于微软开发平台构建和使用私有NuGet托管库
- di.xml
- 一对一关联模型,HAS_ONE
- 蚂蚁风险大脑亮相ATEC城市峰会:为数字经济时代做好“安全守护”
- 6.oop-类和对象
- QTP 自动货测试桌面程序-笔记(添加控件仓库并关联到action)
- Spring-AOP环绕监听出错
- AndroidStudio_RecyclerView
- WinForm 中 comboBox控件数据绑定
- Android自定义View学习(四)
- Spring总结 3.AOP(xml)
- spring cloud 加入配置中心后的 部分 配置文件优先级
- ios8 UITableView section不显示
- object-oriented second work