https://leetcode.com/problems/battleships-in-a-board/?tab=Description
找出连续X(横向或者纵向)的个数
public class Solution {
public int countBattleships(char[][] board) {
if (board == null || board.length == 0) {
return 0;
}
int res = 0;
for (int i = 0; i < board.length; i++) {
for (int j = 0; j < board[0].length; j++) {
if (board[i][j] == '.') {
continue;
}
if (i > 0 && board[i - 1][j] == 'X') {
continue;
}
if (j > 0 && board[i][j - 1] == 'X') {
continue;
}
res++;
}
}
return res;
}
}
转载请注明原文地址: https://ju.6miu.com/read-19829.html