c++ - 我想我并没有越界,但在解决 leetcode 上的 SURROUNDED REGIONS 问题时仍然出现该错误。请帮帮我
问题描述
出现错误------->AddressSanitizer:DEADLYSIGNAL
==31==错误:AddressSanitizer:地址 0x7ffdad997ff4 上的堆栈溢出(pc 0x000000345ac1 bp 0x7ffdad998040 sp 0x7ffdad997fc0 T0)==31==中止......请帮帮我。提前致谢
bool dfs(int i,int j,int m,int n,vector<vector<char>>&v){
if(i>=m||i<0||j>=n||j<0){
return false;
}
if(v[i][j]=='X'){
return true;
}
bool left=dfs(i,j-1,m,n,v);
bool right=dfs(i,j+1,m,n,v);
bool top=dfs(i-1,j,m,n,v);
bool bottom=dfs(i+1,j,m,n,v);
if(left&&right&&top&&bottom){
v[i][j]='X';
return true;
}
return false;
}
void solve(vector<vector<char>>& board) {
int m=board.size();
int n=board[0].size();
for(int i=1;i<m-1;i++){
for(int j=1;j<n-1;j++){
if(board[i][j]=='O'){
bool temp= dfs(i,j,m,n,board);
}
}
}
return;
}
解决方案
推荐阅读
- r - ggplot - R - 冲积图 - 条形之间的空间更大
- mysql - MySQL binlogs 到 BigQuery,什么是复制的好设计?
- c# - Xamarin MainPage 错误:当前上下文中不存在名称
- linux - Logstash - 用 grok 解析数据
- ibm-cloud - 是否可以将自由批处理日志发送到控制台
- batch-file - 如何编写一个批处理文件以每 10 毫秒 ping 一次?
- terraform - terraform 12 嵌套映射
- pyinstaller - 在使用 PyInstaller 创建的可执行文件中导入行为库
- mongodb - 更新嵌套文档的所有字段
- javascript - laravel 7 幻灯片库 onclick 选项