private List<Point> getNeighbors(Point p, int[][] grid, boolean[][] visited, int n, int m) {
        List<Point> resultList = new ArrayList<>();
        if(p.x > 0 && grid[p.x -1][p.y] == 0 && !visited[p.x - 1][p.y])
            resultList.add(new Point(p.x -1, p.y, p.dist + 1));
        if(p.x < n - 1 && grid[p.x + 1][p.y] == 0 && !visited[p.x + 1][p.y])
            resultList.add(new Point(p.x + 1, p.y, p.dist + 1));
        if(p.y > 0 && grid[p.x][p.y - 1] == 0 && !visited[p.x][p.y - 1])
            resultList.add(new Point(p.x, p.y - 1, p.dist + 1));
        if(p.y < m - 1 && grid[p.x][p.y + 1] == 0 && !visited[p.x][p.y + 1])
            resultList.add(new Point(p.x, p.y + 1, p.dist + 1));

        return resultList;
    }
Date 03/25/2016
@author Tushar Roy

Shortest Distance from All Buildings
https://leetcode.com/problems/shortest-distance-from-all-buildings/
src/com/interview/multiarray/ShortestDistanceFromAllBuildings.java