class Solution {
public static int countBattleships(char[][] board) {
int i,j;
int boardRowSize = board.length;
int boardColSize = board[0].length;
int count = 0;
for(i=0;i<boardRowSize;++i)
for(j=0;j<boardColSize;++j){
if((board[i][j]=='X')&&(i==0||board[i-1][j]=='.')&&(j==0||board[i][j-1]=='.'))
++count;
}
return count;
}
}
leetcode419甲板上的战舰
最新推荐文章于 2022-02-17 12:10:32 发布