675:为高尔夫比赛砍树(添加注释)

This commit is contained in:
轩辕龙儿 2022-05-24 10:05:47 +08:00
parent 83dc9f3b9f
commit aead51e257

View File

@ -74,11 +74,18 @@ public class CutOffTreesForGolfEvent {
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
public int cutOffTree(List<List<Integer>> forest) {
/*
起始位置不可到达的情况即坐标0,0位置为0
*/
if (forest.get(0).get(0) == 0) {
return -1;
}
int xL = forest.size();
int yL = forest.get(0).size();
/*
按照顺序排列需要砍的树记录每棵树的位置
*/
TreeMap<Integer, Pair<Integer, Integer>> map = new TreeMap<>();
for (int i = 0; i < xL; i++) {
List<Integer> list = forest.get(i);
@ -102,6 +109,9 @@ public class CutOffTreesForGolfEvent {
continue;
}
boolean bl = false;
/*
计算到达下一棵需要砍树的步数
*/
while (!queue.isEmpty() && !bl) {
int nums = queue.size();
step++;