Who can help me about the "Runtime Error" condition


  • 0
    Q

    here is my code

    class Solution {
    public:
        /**
         * @param matrix a matrix of m x n elements
         * @return an integer array
         */
        vector<int> spiralOrder(vector<vector<int>>& matrix) {
            // Write your code here
            vector<int> result = {};
            if(matrix.size() == 0) return result;
            if(matrix[0].size() == 0) return result;
            spiralOrder(matrix, 0, 0, matrix.size()-1, matrix[0].size()-1, result);
            return result;
        }
    private:
        void spiralOrder(vector<vector<int>>& matrix, int x1, int y1, int x2, int y2, vector<int>& result){
            
            int i;
            if(x1 > x2 || y1 > y2) return;
            for(i = y1; i <= y2; i++){
                result.push_back(matrix[x1][i]);
            }
            if(x1 == x2) return;
            for(i = x1+1; i <= x2; i++){
                result.push_back(matrix[i][y2]);
            }
            if(y1 == y2) return;
            for(i = y2-1; i >= y1; i--){
                result.push_back(matrix[x2][i]);
            }
            if(x1+1 == x2) return;
            for(i = x2-1; i >= x1-1; i--){
                result.push_back(matrix[i][y1]);
            }
            spiralOrder(matrix, x1+1, y1+1, x2-1, y2-1, result);
            return;
        }
        
    };
    

    the result is

    Submission Result: Runtime Error More Details 
    
    Runtime Error Message:
    reference binding to null pointer of type 'value_type'
    Last executed input:
    [[1,2,3],[4,5,6],[7,8,9]]
    

    I don't know what's wrong, who can help me.


  • 0
    Y
    This post is deleted!

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.