dimanche 18 juillet 2021

Line 1034: Char 34: runtime error: applying non-zero offset 8 to null pointer (stl_vector.h) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior

class Solution {
public:
    static bool nonDec(vector<int> a, vector<int> b){
        return ((a[0]*a[1])>(b[0]*b[1]));
    };
    
    int maxHeight(vector<vector<int>>& cuboids) {
        int n=cuboids.size();
        int rotLength=3*n;
        vector<vector<int>> rot(rotLength);
        //rot 0->length//1->width//2->height
        int index=0;
        for(int i=0;i<n;i++){
            rot[index][2]=cuboids[i][2];
            rot[index][0]=cuboids[i][0];
            rot[index][1]=cuboids[i][1];
            index++;
            
            rot[index][2]=cuboids[i][0];
            rot[index][1]=max(cuboids[i][1],cuboids[i][2]);
            rot[index][1]=min(cuboids[i][1],cuboids[i][2]);
            index++;
            
            
            rot[index][2]=cuboids[i][1];
            rot[index][1]=max(cuboids[i][0],cuboids[i][2]);
            rot[index][1]=min(cuboids[i][0],cuboids[i][2]);
            index++;
        }
        n=3*n;
        sort(rot.begin(),rot.end(),nonDec);
        vector<int> msh;
        for(int i=0;i<n;i++){ msh[i]=rot[i][2];}
        for(int i=1;i<n;i++){
            for(int j=0;j<i;j++){
                if(rot[i][1]<=rot[j][1] && rot[i][0]<=rot[j][0] && rot[i][2]<=rot[j][2] && msh[i]<msh[j]+rot[i][2]){
                    msh[i]=msh[j]+rot[i][2];
                }
            }
        }
        int maxValue=0;
        for(int i=0;i<n;i++){
            if(msh[i]>maxValue){
                maxValue=msh[i];
            }
        }
        return maxValue;
    }
};

Link to problem: https://leetcode.com/problems/maximum-height-by-stacking-cuboids/ Error : Line 1034: Char 34: runtime error: applying non-zero offset 8 to null pointer (stl_vector.h) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_vector.h:1043:34

Aucun commentaire:

Enregistrer un commentaire