有没有大佬能帮忙看看哪里有问题,50%通过率。

public int numberOfPatrolBlocks(int[][] block) {
this.block = block;
visited = new boolean[block.length][block[0].length];
return patrol(0, 0, 0); // 从(0, 0)开始,面向右边
}
private int patrol(int x, int y, int direction) {
if (x < 0 || x >= block.length || y < 0 || y >= block[0].length || block[x][y] == 1 || visited[x][y]) {
return 0;
}
visited[x][y] = true;
int count = 1;
for (int i = 0; i < 4; i++) {
int newDirection = (direction + i) % 4;
int nx = x + deltas[newDirection][0];
int ny = y + deltas[newDirection][1];
if (nx >= 0 && nx < block.length && ny >= 0 && ny < block[0].length && block[nx][ny] == 0 && !visited[nx][ny]) {
count += patrol(nx, ny, newDirection);
}
}
return count;
}
}