mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-30 15:58:44 +00:00
Update 13. 机器人的运动范围.md
题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# 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
|
||||
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 cols;
|
||||
private int threshold;
|
||||
private int[][] digitSum;
|
||||
|
||||
public int movingCount(int threshold, int rows, int cols) {
|
||||
this.rows = rows;
|
||||
this.cols = cols;
|
||||
this.threshold = threshold;
|
||||
public int wardrobeFinishing(int m, int n, int cnt) {
|
||||
this.rows = m;
|
||||
this.cols = n;
|
||||
this.threshold = cnt;
|
||||
initDigitSum();
|
||||
boolean[][] marked = new boolean[rows][cols];
|
||||
dfs(marked, 0, 0);
|
||||
return cnt;
|
||||
return res;
|
||||
}
|
||||
|
||||
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;
|
||||
if (this.digitSum[r][c] > this.threshold)
|
||||
return;
|
||||
cnt++;
|
||||
res++;
|
||||
for (int[] n : next)
|
||||
dfs(marked, r + n[0], c + n[1]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user