Skip to content

Commit 15a9c29

Browse files
committed
Improved minimumDays() method.
1 parent 4232185 commit 15a9c29

File tree

1 file changed

+5
-7
lines changed
  • src/main/java/com/github/underscore

1 file changed

+5
-7
lines changed

src/main/java/com/github/underscore/U.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3743,9 +3743,7 @@ public boolean test(T value) {
37433743

37443744
public static int minimumDays(int rows, int columns, List<List<Integer>> grid) {
37453745
Queue<int[]> queue = new LinkedList<int[]>();
3746-
int target = rows * columns;
37473746
int cnt = 0;
3748-
int res = 0;
37493747
for (int i = 0; i < rows; i++) {
37503748
for (int j = 0; j < columns; j++) {
37513749
if (grid.get(i).get(j) == 1) {
@@ -3754,12 +3752,12 @@ public static int minimumDays(int rows, int columns, List<List<Integer>> grid) {
37543752
}
37553753
}
37563754
}
3757-
Integer res1 = getInteger(rows, columns, grid, queue, target, cnt, res);
3758-
return res1 != null ? res1 : -1;
3755+
return getInteger(rows, columns, grid, queue, cnt);
37593756
}
37603757

3761-
private static Integer getInteger(int rows, int columns, List<List<Integer>> grid, Queue<int[]> queue, int target,
3762-
int cnt, int res) {
3758+
private static int getInteger(int rows, int columns, List<List<Integer>> grid, Queue<int[]> queue, int cnt) {
3759+
int target = rows * columns;
3760+
int res = 0;
37633761
int[][] dirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
37643762
while (!queue.isEmpty()) {
37653763
int size = queue.size();
@@ -3780,7 +3778,7 @@ private static Integer getInteger(int rows, int columns, List<List<Integer>> gri
37803778
}
37813779
res++;
37823780
}
3783-
return null;
3781+
return -1;
37843782
}
37853783

37863784
public static List<String> topNCompetitors(int numCompetitors, int topNCompetitors, List<String> competitors,

0 commit comments

Comments
 (0)