onnhyd / all_codes_with_bug

In this repository I will add all my code those I find correct but are not working somehow.
MIT License
2 stars 7 forks source link

Number of Distinct Islands #5

Open onnhyd opened 2 years ago

onnhyd commented 2 years ago

image

Problem Link

class Solution {
  public:

  bool isValid(int i, int j, vector<vector<int>>& g)
  {
      if(i < 0 || j < 0 || i >= g.size() || j >= g[0].size() || g[i][j] == 0)return false;
      return true;
  }
  void DFS(stack<string>&t, int i, int j, vector<vector<int>>&grid)
  {
      grid[i][j] = 0;

      if(isValid(i + 1, j, grid))
      {
          t.push("down");

          DFS(t, i + 1, j, grid);

      }
       if(isValid(i - 1, j, grid))
      {
          t.push("up");

          DFS(t, i - 1, j, grid);

      }
       if(isValid(i , j + 1, grid))
      {
          t.push("right");

          DFS(t, i, j + 1, grid);

      }
       if(isValid(i , j - 1, grid))
      {
          t.push("left");

          DFS(t, i, j - 1, grid);

      }

  }
    int countDistinctIslands(vector<vector<int>>& grid) {
        set<stack<string>>st;
        int n = grid.size(), m = grid[0].size(), ans = 0;

        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < m; j++)
            {
                if(grid[i][j] == 1)
                {
                    stack<string>temp;
                    DFS(temp, i, j, grid);
                    if(st.find(temp) == st.end())
                    {
                        ans++;
                        st.insert(temp);
                    }

                }
            }
        }
        return ans;
    }
};
narayan954 commented 2 years ago

I can solve that, can you assign it to me?

destroyer5067 commented 1 year ago

Assign this to me, I am expert in graph problems

narayan954 commented 1 year ago

@destroyer5067 You might be an expert but issues are assigned first come first serve . Better luck next time :P

aryanayush012 commented 1 year ago

I want To contribute .Please assign this to me. @destroyer5067

Dhanunjay18 commented 1 year ago

Can u please assign it to me