小编hea*_*ter的帖子

第 924 行:字符 9:运行时错误:引用绑定到类型为“int”的空指针 (stl_vector.h)

在 leetcode 上运行以下代码时出现运行时错误。当我删除用户定义的比较器功能时,它工作正常。但是使用用户定义的比较器函数,它会给出如下运行时错误:

第 924 行:字符 9:运行时错误:引用绑定到类型为“int”(stl_vector.h)的空指针总结:UndefinedBehaviorSanitizer:undefined-behavior /usr/bin/../lib/gcc/x86_64-linux-gnu/8 /../../../../include/c++/8/bits/stl_vector.h:933:9

class Solution {
private:
    static bool comp (vector<int> p1, vector<int> p2) {
        if(p1[0] < p2[0] || p1[1] < p2[1])
            return true;
        else
            return false;
    }
    
public:
    int maxEnvelopes(vector<vector<int>>& envelopes) {
        if (envelopes.empty())
            return 0;
        sort(envelopes.begin(), envelopes.end(), comp);
        vector<int> dp(envelopes.size(), 1);
        int res = 0;
        
        for (int i = 0; i < envelopes.size(); i++) {
            for (int j = i-1; j >=0; j--) {
                if (envelopes[j][0] < envelopes[i][0] && envelopes[j][1] < envelopes[i][1] …
Run Code Online (Sandbox Code Playgroud)

c++

3
推荐指数
1
解决办法
8390
查看次数

标签 统计

c++ ×1