1
+ class Solution {
2
+ public:
3
+ void solve (vector<vector<char >>& board) {
4
+ int m = board.size ();
5
+ int n = board[0 ].size ();
6
+ std::vector<std::pair<int , int >> allOs;
7
+
8
+ // all Os on edge
9
+ for (int i = 0 ; i < n; ++i){
10
+ // firstRow
11
+ if (board[0 ][i] == ' O' ){
12
+ allOs.emplace_back (0 ,i);
13
+ }
14
+ // lastRow
15
+ if (board[m-1 ][i]==' O' ){
16
+ allOs.emplace_back (m-1 ,i);
17
+ }
18
+ }
19
+
20
+ for (int j = 1 ; j < m-1 ; ++j){
21
+ // first column. without corner
22
+ if (board[j][0 ]==' O' ){
23
+ allOs.emplace_back (j,0 );
24
+ }
25
+ // last column without corner
26
+ if (board[j][n-1 ]==' O' ){
27
+ allOs.emplace_back (j,n-1 );
28
+ }
29
+ }
30
+ std::cout<<allOs.size ()<<std::endl;
31
+ }
32
+ void nearByO (vector<vector<char >>& board, std::pair<int , int >& coordinate){
33
+ int y = coordinate.first ;
34
+ int x = coordinate.second ;
35
+
36
+ std::vector<std::pair<int ,int >> directions = {
37
+ {1 , 0 },
38
+ {0 , 1 },
39
+ {0 , -1 },
40
+ {-1 , 0 }
41
+ }
42
+
43
+ for (const std::pair<int , int >& dir : directions){
44
+ int newY = y + dir.first ;
45
+ int newX = x + dir.second ;
46
+ if (newY >=0 && newY < board.size () && newX >= 0 && newX < board[0 ].size ())){
47
+ if (board[newY][newX] == ' O' )
48
+ }
49
+
50
+ }
51
+
52
+ if (board[y+1 ][x] ==' O' ){
53
+ allOs.emplace_back (y+1 ,x);
54
+ }
55
+ if (board[y-1 ][x] ==' O' )
56
+ if (board[y][x+1 ] ==' O' )
57
+ if (board[y][x-1 ] ==' O' )
58
+ }
59
+ };
0 commit comments