public int minPathSum(int[][] grid) {
        if (grid == null || grid.length == 0) {
            return 0;
        }
        
        int[][] result = new int[grid.length][grid[0].length];
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[0].length; j++) {
                result[i][j] = -1;
            }
        }
        
        _minPathSum(grid, result, grid.length, grid[0].length);
        return result[grid.length-1][grid[0].length-1];
    }