-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.java
More file actions
18 lines (17 loc) · 1.36 KB
/
Copy pathSolution.java
File metadata and controls
18 lines (17 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Solution
{
public int numEnclaves(int[][] A)
{
int count = 0;
int n = A.length; // number of rows int m = A[0].length; // number of columns for (int i = 0; i
// < m; i++) { if (A[0][i] == 1) { _reachBoundary(0, i, n, m, A);
// } if (A[n - 1][i] == 1) { _reachBoundary(n - 1, i, n, m, A);
// } } for (int i = 0; i < n; i++) { if (A[i][0] == 1) {
// _reachBoundary(i, 0, n, m, A); } if (A[i][m - 1] == 1) {
// _reachBoundary(i, m - 1, n, m, A); } } for (int i = 0; i < n; i++) {
// for (int j = 0; j < m; j++) { if (A[i][j] == 1) {
// count++; } } } return count; } private void _reachBoundary
// (int i, int j, int n, int m, int[][] A) { if (i < 0 || i >= n || j < 0 || j >= m) {
// return; } if (A[i][j] == 0 || A[i][j] == -1) { return; }
// A[i][j] = -1; _reachBoundary(i + 1, j, n, m, A); _reachBoundary(i - 1, j, n, m, A);
// _reachBoundary(i, j + 1, n, m, A); _reachBoundary(i, j - 1, n, m, A); }}