public class Solution {
public int CountBattleships(char[,] board) {
var row = board.GetLength();//3行
var col = board.GetLength();//4列 int count = ;
for (int i = ; i < row; i++)
{
for (int j = ; j < col; j++)
{
if (board[i, j] == 'X' && (i == || board[i - , j] != 'X') && (j == || board[i, j - ] != 'X'))
{
count++;
}
}
}
return count;
}
}

https://leetcode.com/problems/battleships-in-a-board/#/description

leetcode419的更多相关文章

  1. [Swift]LeetCode419. 甲板上的战舰 | Battleships in a Board

    Given an 2D board, count how many battleships are in it. The battleships are represented with 'X's, ...

随机推荐

  1. BZOJ4561 JLoi2016 圆的异或并 【扫描线】【set】*

    BZOJ4561 JLoi2016 圆的异或并 Description 在平面直角坐标系中给定N个圆.已知这些圆两两没有交点,即两圆的关系只存在相离和包含.求这些圆的异或面积并.异或面积并为:当一片区 ...

  2. 剑指offer第六章

    剑指offer第六章 1.数字在排序数组中出现的次数 统计一个数字在排序数组中出现的次数.例如输入排序数组{1,2,3,3,3,3,4,5}和数字3,由于3在数组中出现了4次,所以输出4 分析:思路1 ...

  3. 《DSP using MATLAB》示例Example 8.29

    %% ------------------------------------------------------------------------ %% Output Info about thi ...

  4. 《DSP using MATLAB》示例Example 8.28

    %% ------------------------------------------------------------------------ %% Output Info about thi ...

  5. curl 错误 [globbing] illegal character in range specification at pos

    现象 在使用curl 进行ipv6请求的时候 curl -v "http://[1:1::1]/test.html" 发生了一个错误,报错是 [globbing] illegal ...

  6. luarocks 安装

    1. linux 安装 wget https://luarocks.org/releases/luarocks-2.4.1.tar.gz tar zxpf luarocks-2.4.1.tar.gz ...

  7. sql的一些事件处理

    select getdate() select Convert(varchar(10),getdate(),120) yyyy-mm-ddselect Convert(varchar(20),getd ...

  8. 树的遍历——pat1043

    http://pat.zju.edu.cn/contests/pat-a-practise/1043 给予N个数字组成二叉搜索树,判断这个数列是否由先序遍历得出或是镜像先序遍历得出,若是则输出相应的后 ...

  9. send函数和recv函数

    1.send 函数 int send( SOCKET s, const char FAR *buf, int len, int flags );   不论是客户还是服务器应用程序都用send函数来向T ...

  10. python set集合 以及 深浅拷贝

    set集合 特点: 无序, 不重复, 元素必须可哈希(不可变) 作用: 去重复 本身是可变的数据类型. 有增删改查操作. frozenset()冻结的集合. 不可变的. 可hash的 深浅拷贝() 1 ...