title: Number of Island leetcode python
body: <p>The question reads as the following:  Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.</p>
  
  <pre><code>class Solution:
      def numIslands(self, grid: List[List[str]]) -&gt; int:
          # use dfs / replace the island's elements with a sign "."
          a = len(grid)
          b = len(grid[0])
          num = 0
  
  
          for i in range(0 , a-1):
              for j in range(0 , b-1):
                  if grid[i][j] == '1':
                      num += 1
                      self.dfs(grid , i , j)
  
          return num
  
      def dfs(self, grid , x , y):
  
          if x &lt; 0 or y &lt; 0 or x &gt;= len(grid[0]) or y &gt;= len(grid) or grid[x][y] == '0' or grid[x][y] == ".": # if out of boundary
              return
  
          grid[x][y] = "."        
          # if 1's has only one neighbor
  
          self.dfs(grid , x-1 , y)   # check 4 edges of water
          self.dfs(grid, x+1 , y)
          self.dfs(grid , x , y+1)
          self.dfs(grid , x , y- 1)
  </code></pre>
  
  <p>This code only works for this output: [["1","1","1","1","0"],["1","1","0","1","0"],["1","1","0","0","0"],["0","0","0","0","0"]]</p>
  
  <p>However, it does not work for this output: [["1","1","0","0","0"],["1","1","0","0","0"],["0","0","1","0","0"],["0","0","0","1","1"]]</p>
  
  <p>I am trying to use the dfs method. Thus, if x is in the array, function dfs would check the neighbor elements from 4 sides whether it is "1" or not, if it is "1", then it is replaced by ".". otherwise, if the element is "0", the recursive loop stops. Once all recursive loop stops for every possible combinations, The count is incremented by 1. Then the program runs to find other "X". </p>
  
  <p>However, the program does not work properly. Therefore, Could anyone helps me to find problems in this code?</p>