Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. class Solution {
  2. public:
  3. int countBattleships(vector<vector<char>>& board) {
  4. int cnt = 0;
  5. if(board.empty()) return cnt;
  6. if(board[0].empty()) return cnt;
  7.  
  8. for(int i = 0; i < board.size(); i++) {
  9. for(int j = 0; j < board[0].size(); j++) {
  10. if(board[i][j] == '.') continue;
  11. if(i > 0 && board[i - 1][j] == 'X') continue;
  12. if(j > 0 && board[i][j - 1] == 'X') continue;
  13. cnt++;
  14. }
  15. }
  16. return cnt;
  17. }
  18. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement