-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution2850.java
More file actions
38 lines (33 loc) · 1.09 KB
/
Copy pathSolution2850.java
File metadata and controls
38 lines (33 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package leecode;
import java.util.ArrayList;
import java.util.List;
/**
* 2850. 将石头分散到网格图的最少移动次数
*/
public class Solution2850 {
public static void main(String[] args) {
Solution2850 v = new Solution2850();
System.out.println(v.minimumMoves(new int[][]{new int[]{1,1,0},new int[]{1,1,1},new int[]{1,2,1}}));
System.out.println(v.minimumMoves(new int[][]{new int[]{1,3,0},new int[]{1,0,0},new int[]{1,0,3}}));
}
public int minimumMoves(int[][]grid) {
List<int[]> moreList = new ArrayList<>();
List<int[]> lessList = new ArrayList<>();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (grid[i][j] > 1) {
for (int k = 1; k < grid[i][j]; k++) {
moreList.add(new int[]{i,j});
}
} else if (grid[i][j] == 0) {
lessList.add(new int[]{i,j});
}
}
}
if (moreList.isEmpty()) {
return 0;
}
//todo
return 888;
}
}