简体   繁体   English

leetcode 中的运行时错误 AddressSanitizer:DEADLYSIGNAL

[英]Runtime Error AddressSanitizer:DEADLYSIGNAL in leetcode

I am getting the following Runtime error:

AddressSanitizer:DEADLYSIGNAL
=================================================================
==32==ERROR: AddressSanitizer: stack-overflow on address 0x7ffcdc3e2ff8 (pc 0x00000038409c bp 0x7ffcdc3e3020 sp 0x7ffcdc3e3000 T0)
==32==ABORTING

while solving https://leetcode.com/problems/unique-paths-iii/同时解决https://leetcode.com/problems/unique-paths-iii/
I am unable to figure out the root cause of it.我无法弄清楚它的根本原因。
My source code is as follows:我的源代码如下:

#define vvi vector<vector<int> >
#define vi vector<int>

class Solution {
public:
    int helper(vvi &grid, vvi &dp, int m, int n, int i, int j) {
        if(i < 0 || i >= n || j < 0 || j >= m || -1 == grid[i][j])
           return 0;

        if(0 == dp[i][j]) {
            if(2 == grid[i][j])
                dp[i][j] = 1;
            else
                dp[i][j] = helper(grid, dp, m, n, i - 1, j) +
                           helper(grid, dp, m, n, i, j + 1) +
                           helper(grid, dp, m, n, i + 1, j) +
                           helper(grid, dp, m, n, i, j - 1);
        }

        return dp[i][j];
    }

    int uniquePathsIII(vector<vector<int>>& grid) {
        if(grid.size() == 0)
            return 0;

        int n = grid.size();
        int m = grid[0].size();
        vvi dp(n, vi(m, 0));

        return helper(grid, dp, m, n, 0, 0);
    }
};

Thanks for any help:)谢谢你的帮助:)

The issue has been resolved.问题已解决。 It was happening because the visited nodes were being pushed onto the stack again for computation and this was resulting in infinite recursion.发生这种情况是因为被访问的节点再次被推入堆栈进行计算,这导致了无限递归。

It was solved using a visited array that ensures that a specific block in the path is checked only once.它是使用访问数组来解决的,该数组确保路径中的特定块只检查一次。

If you are facing similar problems then check if your recursion will terminate or loop endlessly.如果您遇到类似的问题,请检查您的递归是否会终止或无限循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AddressSanitizer:比较时出现 DEADLYSIGNAL 错误 - AddressSanitizer:DEADLYSIGNAL error on comparison 地址消毒剂:DEADLYSIGNAL - AddressSanitizer:DEADLYSIGNAL 为什么选择 AddressSanitizer:DEADLYSIGNAL? - Why AddressSanitizer:DEADLYSIGNAL? AddressSanitizer:DEADLYSIGNAL 错误,尝试使用堆栈运行代码以获得有效的括号问题集 - AddressSanitizer:DEADLYSIGNAL error when trying to run code using stack for valid parenthesis problem set LeetCode为什么会给出错误:AddressSanitizer:堆缓冲区溢出? - Why does LeetCode give the ERROR : AddressSanitizer: heap-buffer-overflow? 错误:UndefinedBehaviorSanitizer:DEADLYSIGNAL - ERROR: UndefinedBehaviorSanitizer:DEADLYSIGNAL 为什么我在 leetcode 上收到 AddressSanitizer: heap-buffer-overflow on address 0x602000000058 错误? - Why am I getting AddressSanitizer: heap-buffer-overflow on address 0x602000000058 error on leetcode? LeetCode C++ 将 char[] 转换为字符串,抛出 AddressSanitizer: stack-buffer-overflow 错误 - LeetCode C++ Convert char[] to string, throws AddressSanitizer: stack-buffer-overflow error 为什么我在 leetcode 中出现运行时错误? - Why am i getting runtime error in leetcode? Partion Equal Subset Sum Leetcode: 运行时错误 - Partion Equal Subset Sum Leetcode : RUNTIME ERROR
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM