Line 1034: Char 9: runtime error: reference binding to null pointer of type 'std::vector<int, std::allocator<int>>' (stl_vector.h)

Viewed 19

I was doing a Leetcode question to rotate a matrix by 90 degree, but I am getting a null pointer exception.

Line 1034: Char 9: runtime error: reference binding to null pointer of type 'std::vector<int, std::allocator>' (stl_vector.h) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_vector.h:1043:9

Please see whats wrong in my code.

class Solution {
public:
    vector<vector<int>> rotate(vector<vector<int>>& matrix) {
       vector<vector<int>> dummy;
       for(int i = 0;i<matrix.size();i++){
            for(int j = 0;j<matrix[0].size();j++){
                dummy[i][j]= matrix[i][j];
            }
        }
        return dummy;
    }
};

This is not the actual code for the question, since i was getting error. I just tried to put the values of the matrix in a dummy martix,

0 Answers
Related