Skip to content

Commit 2d901bc

Browse files
committed
Runtime: 513 ms (Top 35.90%) | Memory: 64.7 MB (Top 53.80%)
1 parent 626ffcd commit 2d901bc

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1+
// Runtime: 513 ms (Top 35.90%) | Memory: 64.7 MB (Top 53.80%)
12
class Solution {
23
public:
34
int dx[4]={-1,1,0,0};
45
int dy[4]={0,0,1,-1};
56
bool solve(vector<vector<char>>& grid,int i,int j,int m,int n,int x,int y,vector<vector<int>>&vis,char startChar){
6-
vis[i][j]=1;
7+
vis[i][j]=1;
78
for(int k=0;k<4;k++){
89
int xx=i+dx[k];
910
int yy=j+dy[k];
1011
if(xx>=0 && yy>=0 && xx<m && yy<n && grid[xx][yy]==startChar && !(x == xx && y == yy)){
1112
if(vis[xx][yy] || solve(grid, xx , yy , m , n, i, j,vis,startChar))
12-
return true;
13+
return true;
1314
}
1415
}
1516
return false;
1617
}
17-
18+
1819
bool containsCycle(vector<vector<char>>& grid) {
1920
int m=grid.size();
2021
int n=grid[0].size();
21-
vector<vector<int>>vis(m,vector<int>(n,0));
22+
vector<vector<int>>vis(m,vector<int>(n,0));
2223
for(int i=0;i<m;i++){
2324
for(int j=0;j<n;j++){
2425
if(!vis[i][j] && solve(grid,i,j,m,n,-1,-1,vis,grid[i][j])){
2526
return true;
2627
}
2728
}
28-
}
29+
}
2930
return false;
3031
}
31-
};
32+
};

0 commit comments

Comments
 (0)