Soluation:

```
class Solution {
public:
int countBattleships(vector<vector<char>>& board) {
int row = board.size();
if (0== row) {
return 0;
}
int col = board[0].size();
int count = 0;
for(int i = 0; i < row; i++) {
for(int j = 0; j < col; j++) {
if (board[i][j] == 'X' &&
(i == 0 || board[i-1][j] == '.' ) &&
(j == 0 || board[i][j-1] == '.')){
count++;
}
}
}
return count;
}
};
```