File tree 1 file changed +39
-0
lines changed
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public:
3
+ void fillcolor (vector<vector<char >>&board,int x,int y){
4
+ if (x<0 ||y<0 ||x>=board.size ()||y>=board[0 ].size ()){
5
+ return ;
6
+ }
7
+ if (board[x][y]==' X' ||board[x][y]==' C' ){
8
+ return ;
9
+ }
10
+ if (board[x][y]==' O' ){
11
+ board[x][y]=' C' ;
12
+ }
13
+ fillcolor (board,x-1 ,y);
14
+ fillcolor (board,x,y-1 );
15
+ fillcolor (board,x+1 ,y);
16
+ fillcolor (board,x,y+1 );
17
+
18
+ }
19
+ void solve (vector<vector<char >>& board) {
20
+ for (int i=0 ;i<board.size ();i++){
21
+ for (int j=0 ;j<board[0 ].size ();j++){
22
+ if (i==0 ||j==0 ||i==board.size ()-1 ||j==board[0 ].size ()-1 ){
23
+ fillcolor (board,i,j);
24
+ }
25
+ }
26
+ }
27
+ for (int i=0 ;i<board.size ();i++){
28
+ for (int j=0 ;j<board[0 ].size ();j++){
29
+ if (board[i][j]==' C' ){
30
+ board[i][j]=' O' ;
31
+ }
32
+ else {
33
+ board[i][j]=' X' ;
34
+ }
35
+ }
36
+ }
37
+
38
+ }
39
+ };
You can’t perform that action at this time.
0 commit comments