小工具知识网

当前位置: 首页 > 行业知识 > LeetCode:Line 1037: Char 34: runtime error: addition of unsigned offset to 0x502000000090 overflowed

行业知识

LeetCode:Line 1037: Char 34: runtime error: addition of unsigned offset to 0x502000000090 overflowed

2026-11-07 04:31:09 来源:互联网转载

错误情况(一)

错误信息

在���刷47.全排列II时,写了如下代码:

()
class Solution {public:    void dfs(vector& path, unordered_set& st, vector& res, vector& nums){        if(path.size() == nums.size()){            res.push_back(path);            return;        }        for(int i = 0;i  

出现如下错误信息:

Line 1037: Char 34: runtime error: addition of unsigned offset to 0x502000000090 overflowed to 0x50200000008c (stl_vector.h)SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_vector.h:1046:34

错误定位

通过注释代码的方法,定位到错误的位置在dfs函数里的if判断:

()
if( !i && nums[i] == nums[i - 1] && st.find(i - 1) == st.end()) continue;

错误原因

当i为0元素时,会执行nums[i] == nums[i - 1],i - 1为负数,作为数组索引是不合法的,因此会报如上错误。换言之,当数组索引是负数时,会出现上述错误。

修改错误

之所以写!i,是因为我的逻辑出错的,应该写i != 0 或者i。

上一篇:联想服务器怎么打开盖?

下一篇:宝塔面板极速安装Lamp环境攻略