首页 > 解决方案 > 我想我并没有越界,但在解决 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;
    
}

标签: c++c++17

解决方案


推荐阅读