Skip to content

Commit b135e91

Browse files
refactor 749
1 parent b598029 commit b135e91

File tree

1 file changed

+5
-59
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+5
-59
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,10 @@
11
package com.fishercoder.solutions;
22

3-
/**
4-
* 749. Contain Virus
5-
*
6-
* A virus is spreading rapidly, and your task is to quarantine the infected area by installing walls.
7-
* The world is modeled as a 2-D array of cells, where 0 represents uninfected cells,
8-
* and 1 represents cells contaminated with the virus.
9-
* A wall (and only one wall) can be installed between any two 4-directionally adjacent cells, on the shared boundary.
10-
* Every night, the virus spreads to all neighboring cells in all four directions unless blocked by a wall.
11-
* Resources are limited. Each day, you can install walls around only one region --
12-
* the affected area (continuous block of infected cells) that threatens the most uninfected cells the following night. There will never be a tie.
13-
* Can you save the day? If so, what is the number of walls required? If not, and the world becomes fully infected, return the number of walls used.
14-
15-
Example 1:
16-
Input: grid =
17-
[[0,1,0,0,0,0,0,1],
18-
[0,1,0,0,0,0,0,1],
19-
[0,0,0,0,0,0,0,1],
20-
[0,0,0,0,0,0,0,0]]
21-
22-
Output: 10
23-
Explanation:
24-
There are 2 contaminated regions.
25-
On the first day, add 5 walls to quarantine the viral region on the left. The board after the virus spreads is:
26-
27-
[[0,1,0,0,0,0,1,1],
28-
[0,1,0,0,0,0,1,1],
29-
[0,0,0,0,0,0,1,1],
30-
[0,0,0,0,0,0,0,1]]
31-
32-
On the second day, add 5 walls to quarantine the viral region on the right. The virus is fully contained.
33-
34-
35-
Example 2:
36-
Input: grid =
37-
[[1,1,1],
38-
[1,0,1],
39-
[1,1,1]]
40-
41-
Output: 4
42-
Explanation: Even though there is only one cell saved, there are 4 walls built.
43-
Notice that walls are only built on the shared boundary of two different cells.
44-
45-
46-
Example 3:
47-
Input: grid =
48-
[[1,1,1,0,0,0,0,0,0],
49-
[1,0,1,0,1,1,1,1,1],
50-
[1,1,1,0,0,0,0,0,0]]
51-
Output: 13
52-
Explanation: The region on the left only builds two new walls.
53-
Note:
54-
The number of rows and columns of grid will each be in the range [1, 50].
55-
Each grid[i][j] will be either 0 or 1.
56-
Throughout the described process, there is always a contiguous viral region that will infect strictly more uncontaminated squares in the next round.
57-
*/
583
public class _749 {
59-
public static class Solution1 {
60-
public int containVirus(int[][] grid) {
61-
return -1;
4+
public static class Solution1 {
5+
//TODO: implement it
6+
public int containVirus(int[][] grid) {
7+
return -1;
8+
}
629
}
63-
}
6410
}

0 commit comments

Comments
 (0)