简体   繁体   English

我正在解决一个 leetcode 问题并收到此错误。 我不知道这意味着什么,因为我对 C++ 比较陌生

[英]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.

相关问题 我正在解决 Set Matrix zeros 并在 C++ 的 LEETCODE 中遇到此错误 - I'm solving Set Matrix zeros and getting this error in LEETCODE in C++ 在使用 AWS IoT Core 运行 C++ 脚本时,我收到了一个致命错误。 我对 C++ 和 IoT Core 比较陌生,但我不明白这里有什么问题 - Upon running a C++ script with AWS IoT Core, I get a fatal error. I am relatively new to C++ and IoT Core but I do not understand what is wrong here 我的 Leetcode 程序出现了超出范围的错误 - I'm getting an out of range error on my Leetcode program C++ 新手,我不确定我做错了什么 - New to C++, I'm not sure what I did wrong 我刚刚开始使用 c++,但我在hackerRank 中遇到此代码错误 - I have just started c++ but I'm getting error in hackerRank for this code C++ 中的 LeetCode 417 解决方案。 我收到堆缓冲区溢出错误 - LeetCode 417 solution in C++. I'm getting a heap buffer overflow error 我在 TSP 的 C++ 解决方案中遇到转换错误 - I'm getting a conversion error in my C++ solution for TSP C ++我期待一个缩小的转换错误,但没有得到它 - C++ I'm expecting a narrowing conversion error but not getting it 在C ++中,使用队列和libcurl时出现错误 - In C++ I'm getting an error when using a queue and libcurl C ++出现我不熟悉的“找不到符号”错误 - C++ Getting a “symbols not found” error that I'm not familiar with
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM