comments for bob solutions
This commit is contained in:
@@ -7,11 +7,13 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
//Nearly correct solution...one/two bugs passed most testcases
|
||||
public class Island {
|
||||
static int N, M;
|
||||
static int[][] grid;
|
||||
static boolean[][] visited;
|
||||
static Map<Integer, Integer> islands = new HashMap<>();
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
StringTokenizer st = new StringTokenizer(br.readLine());
|
||||
@@ -29,7 +31,8 @@ public class Island {
|
||||
br.close();
|
||||
for (int i = 0; i < N; i++) {
|
||||
for (int j = 0; j < M; j++) {
|
||||
if (visited[i][j]) continue;
|
||||
if (visited[i][j])
|
||||
continue;
|
||||
if (grid[i][j] > 0) {
|
||||
islands.put(grid[i][j], islands.getOrDefault(grid[i][j], 0) + 1);
|
||||
search(grid[i][j], i, j);
|
||||
@@ -50,10 +53,11 @@ public class Island {
|
||||
}
|
||||
|
||||
static void search(int val, int i, int j) {
|
||||
if (visited[i][j]) return;
|
||||
if (visited[i][j])
|
||||
return;
|
||||
visited[i][j] = true;
|
||||
for (int dir = 0; dir < 4; dir++) {
|
||||
switch(dir) {
|
||||
switch (dir) {
|
||||
case 0:
|
||||
if (j + 1 < M && grid[i][j + 1] == val) {
|
||||
search(val, i, j + 1);
|
||||
|
||||
Reference in New Issue
Block a user