Use of deleted function ‘Solution::Solution()


  • 0
    R

    enclosed is my code.

    But it output CE:
    Line 50: use of deleted function ‘Solution::Solution()’

    class Solution {
    public:
        int numIslands(vector<vector<char>> &g)
        {
            m=g.size();
            if(m<=0) return 0;
            n=g[0].size();g_=g;
            memset(v, 0, sizeof v);
            int ans=0;
            for(int i=0;i<m;i++) for(int j=0;j<n;j++)
            {
                if(g[i][j]=='1' && !v[i][j])
                {
                    dfs(i, j);ans++;
                }
            }
            return ans;
        }
    private:
        const int dx[4]={-1,1, 0, 0},dy[4]={0, 0, -1, 1};
        int m, n;
        bool v[300][300];
        vector<vector<char>> &g_;
        bool outrange(int i, int j)
        {
            return i>=m || i<0 || j>=n || j<0;
        }
        void dfs(int i, int j)
        {
            if(outrange(i, j) || v[i][j] || g_[i][j]=='0') return ;
            v[i][j]=1;
            for(int k=0;k<4;k++)
            {
                int nx=i+dx[k], ny=j+dy[k];
                dfs(nx, ny);
            }
        }
    };

  • 0
    R

    any poison in my code : )


  • 0
    R

    GCC is not reliable, I define a invalid reference of vector<vector<char>> g

    modify
    vector<vector<char>> &g_;
    to
    vector<vector<char>> g_;

    will get AC.

    A misterious event caught by code copy


Log in to reply
 

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