图论19(Leetcode1020飞地的数量)

代码:

class Solution {
    static int[][] dirs = {{-1,0},{1,0},{0,-1},{0,1}};
    public int numEnclaves(int[][] grid) {
        int sum=0;
        for(int i=0;i0){
                        sum+=num;
                    }
                }
            }
        }
        return sum;

    }
    private int getIsland(int num,int[] start,int[][] grid){
        grid[start[0]][start[1]] = 0;
        for(int i=0;i=0&&x=0&&y=0){
                    num++;
                }
                num = getIsland(num,cur,grid);
            }
        }
        return num;
    }
}

你可能感兴趣的:(图论,java,算法)