[英]I'm solving a leetcode question and getting this error. I have no idea what this mean as I'm relatively new to C++
I'm not able to run the code for a while now what can I do to sort this error out.我现在暂时无法运行代码,我该怎么做才能解决这个错误。
AddressSanitizer: DEADLYSIGNAL ================================================================= ==32==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000000383e8c bp 0x7ffc55bebe50 sp 0x7ffc55bebd20 T0) ==32==The signal is caused by a READ memory access. AddressSanitizer: DEADLYSIGNAL =============================================== ====================32==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000000383e8c bp 0x7ffc55bebe50 sp 0x7ffc55bebd20 T0) ==32==信号引起通过 READ memory 访问。 ==32==Hint: address points to the zero page.
==32==提示:地址指向零页。 #3 0x7f2222e3982f (/lib/x86_64-linux-gnu/libc.so.6+0x2082f) AddressSanitizer can not provide additional info.
#3 0x7f2222e3982f (/lib/x86_64-linux-gnu/libc.so.6+0x2082f) AddressSanitizer 无法提供额外信息。 ==32==ABORTING
==32==正在中止
class Solution {
public:
int firstMissingPositive(vector<int>& nums) {
int n=nums.size();
vector<int>ans(50);
for(int i=0; i<n; i++){
if(nums[i]<0) continue;
ans[nums[i]]++;
}
for(int i=1; i<n; i++){
if(ans[i]==0){
return i;
}
}
return n+1;
}
};
You have an out-of-bounds error.您有一个越界错误。 When you write something like this, make sure at least it has the same number or more elements than your nums array.
当您编写这样的内容时,请确保它至少具有与您的 nums 数组相同或更多的元素。
vector<int>ans(50);
it goes out of the boundary in this loop.它超出了这个循环的边界。
for(int i=0; i<n; i++)
{
if(nums[i]<0) continue;
ans[nums[i]]++;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.