I am back to solving a question on Leetcode - https://leetcode.com/problems/minesweeper/description/. The question basically asks us to implement a mini-version of the minesweeper game (skipped since the exact details are not required).
With some online help from a Java code, I wrote the following code:
class Solution {
public:
vector<vector<char>> updateBoard(vector<vector<char>>& board, vector<int>& click) {
if(board.empty() || board[0].empty()) return vector<vector<char>>();
int m=board.size(), n=board[0].size(), row=click[0], col=click[1];
if(board[row][col]=='M') {
board[row][col]='X';
return board;
}
if(board[row][col]=='E') {
int mineCounter=0;
for(int i=-1; i<2; i++)
for(int j=-1; j<2; j++) {
if(i==0 && j==0) continue;
int r=row+i, c=col+j;
if(r<0 || r>=m || c<0 || c>=n) continue;
if(board[r][c]=='M' || board[r][c]=='X') mineCounter++;
}
if(mineCounter) {
board[row][col]=(char)mineCounter+'0';
return board;
} else {
board[row][col]='B';
for(int i=-1; i<2; i++)
for(int j=-1; j<2; j++) {
if(i==0 && j==0) continue;
int r=row+i, c=col+j;
if(r<0 || r>=m || c<0 ||c>=n) continue;
if(board[r][c]=='E') {
// vector<int> kolloba;
// kolloba.push_back(r);
// kolloba.push_back(c);
updateBoard(board, vector<int> kolloba={r, c});
}
}
}
}
return board;
}
};
I get the following compilation error:
Line 36: expected primary-expression before 'kolloba'
Ah, I know the other way to do this (as commented above); but I fail to understand the reason for compilation error in this particular case. Could someone please point out what am I doing wrong?
Note: Leetcode uses g++ 6.3
with the latest C++14
standard. So, although the above snippet is valid only in C++11
; I don't think that is a problem; I feel I have done some really silly mistake. Could someone please point out?
Aucun commentaire:
Enregistrer un commentaire