gpt4 book ai didi

c++ - 运行时错误 : addition of unsigned offset

转载 作者:行者123 更新时间:2023-12-04 11:59:10 24 4
gpt4 key购买 nike

关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。












想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。

去年关闭。




Improve this question




我正在解决一个关于 Leetcode(捕获雨水)的问题,我编写了我的解决方案,该解决方案已经在我的本地机器以及 GeeksForGeeks 上通过了所有 TC 的测试。代码是:

    int trap(vector<int>& height) {
int size = height.size();
int i,units;

vector<int> l(size),r(size);
l[0] = height[0];
r[size-1] = height[size-1];

for(i=1; i<size; i++){
l[i] = max(height[i-1],l[i-1]);
}

for(i=size-1; i>=0; i--){
r[i-1] = max(r[i],height[i]);
}

for(i=0; i<size; i++){
if((min(l[i],r[i]) == 0) || (min(l[i],r[i])-height[i]<0))
continue;
else{
units +=min(l[i],r[i])-height[i];
}
}
return units;
}

这是我唯一需要编辑的部分。在运行它时,我收到以下错误
Line 928: Char 34: runtime error: addition of unsigned offset to 0x6040000000d0 overflowed to 0x6040000000cc (stl_vector.h)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/stl_vector.h:933:34

我需要一些帮助来找到我遇到缓冲区溢出的地方。提前加油。

最佳答案

这是一个错字,它应该是 i>0 而不是 i>=0。

关于c++ - 运行时错误 : addition of unsigned offset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60977407/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com