mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-11-24 07:13:47 +00:00
Update 13. 机器人的运动范围.md
题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# 13. 机器人的运动范围
|
# 13. 机器人的运动范围
|
||||||
|
|
||||||
[牛客网](https://www.nowcoder.com/practice/6e5207314b5241fb83f2329e89fdecc8?tpId=13&tqId=11219&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
|
[Leetcode](https://leetcode.cn/problems/ji-qi-ren-de-yun-dong-fan-wei-lcof/)
|
||||||
|
|
||||||
## 题目描述
|
## 题目描述
|
||||||
|
|
||||||
@@ -14,20 +14,20 @@
|
|||||||
|
|
||||||
```java
|
```java
|
||||||
private static final int[][] next = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};
|
private static final int[][] next = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};
|
||||||
private int cnt = 0;
|
private int res = 0;
|
||||||
private int rows;
|
private int rows;
|
||||||
private int cols;
|
private int cols;
|
||||||
private int threshold;
|
private int threshold;
|
||||||
private int[][] digitSum;
|
private int[][] digitSum;
|
||||||
|
|
||||||
public int movingCount(int threshold, int rows, int cols) {
|
public int wardrobeFinishing(int m, int n, int cnt) {
|
||||||
this.rows = rows;
|
this.rows = m;
|
||||||
this.cols = cols;
|
this.cols = n;
|
||||||
this.threshold = threshold;
|
this.threshold = cnt;
|
||||||
initDigitSum();
|
initDigitSum();
|
||||||
boolean[][] marked = new boolean[rows][cols];
|
boolean[][] marked = new boolean[rows][cols];
|
||||||
dfs(marked, 0, 0);
|
dfs(marked, 0, 0);
|
||||||
return cnt;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dfs(boolean[][] marked, int r, int c) {
|
private void dfs(boolean[][] marked, int r, int c) {
|
||||||
@@ -36,7 +36,7 @@ private void dfs(boolean[][] marked, int r, int c) {
|
|||||||
marked[r][c] = true;
|
marked[r][c] = true;
|
||||||
if (this.digitSum[r][c] > this.threshold)
|
if (this.digitSum[r][c] > this.threshold)
|
||||||
return;
|
return;
|
||||||
cnt++;
|
res++;
|
||||||
for (int[] n : next)
|
for (int[] n : next)
|
||||||
dfs(marked, r + n[0], c + n[1]);
|
dfs(marked, r + n[0], c + n[1]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user