Skip to content

Commit 112cfab

Browse files
committed
Time: 104 ms (84.45%), Space: 38.3 MB (48.03%) - LeetHub
1 parent ce0252a commit 112cfab

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
class Solution {
2+
public:
3+
4+
vector<int> dx = {1,0};
5+
vector<int> dy = {0,1};
6+
7+
bool dfs(int i, int j, int n, int m, vector<vector<int>>& grid)
8+
{
9+
if(i == n-1 and j == m-1)
10+
return true;
11+
12+
grid[i][j] = 0;
13+
14+
for(int k = 0; k < 2; ++k)
15+
{
16+
int newx = i + dx[k];
17+
int newy = j + dy[k];
18+
19+
if(newx >= 0 and newy >= 0 and newx < n and newy < m and grid[newx][newy] == 1)
20+
{
21+
if(dfs(newx,newy, n,m,grid))
22+
return true;
23+
}
24+
}
25+
return false;
26+
}
27+
28+
bool isPossibleToCutPath(vector<vector<int>>& grid) {
29+
30+
int n = grid.size(), m = grid[0].size();
31+
32+
if(dfs(0,0,n,m,grid) == false)
33+
return true;
34+
35+
if(dfs(0,0,n,m,grid) == false)
36+
return true;
37+
38+
return false;
39+
}
40+
};

0 commit comments

Comments
 (0)