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. Python timedelta

    datetime.timedelta对象代表两个时间之间的的时间差,两个date或datetime对象相减时可以返回一个timedelta对象.   构造函数: class datetime.time ...

  2. Redis学习总结之二——Redis配置文件(Windows版)

    # Redis configuration file example # Note on units: when memory size is needed, it is possible to sp ...

  3. 让ASP.NET第一次请求不变慢

    网页开发者早期最常遇到一个问题,当网站布署到IIS时候,每当IIS或是Application Pool重启后,第一位进入网站的使用者,其体验往往第一个反应就是网站很慢,然后就一直询问IT为什么网站这么 ...

  4. c++学习笔记(4)

    1.non-virtual函数是在编译时完成解析的,根据该对象被调用时的类型来判断!!切记这点. 2.凡基类定义有一个(或多个)虚函数,应该要将其destructor声明为virtual,但不要把de ...

  5. [持续更新]Python 笔记

    本文以 Python 2.7 为基础. lambda 函数实现递归 方法一:传递一个 self 参数 求阶乘: frac = lambda self, x: self(self, x - 1) * x ...

  6. js数组简单总结

    1.创建数组var array = new Array();var array = new Array(size);//指定数组的长度var array = new Array(item1,item2 ...

  7. stm32寄存器版学习笔记05 PWM

    STM32除TIM6和TIM7外都可以产生PWM输出.高级定时器TIM1和TIM8可以同时产生7路PWM,通用定时器可以产生4路PWM输出. 1.TIM1 CH1输出PWM配置步骤 ①开启TIM1时钟 ...

  8. java面试题08

    1.short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? short s1 = 1; s1 = s1 + 1;编译时错误.对于shor ...

  9. jQuery.1.9 live 代替事件 on 新增内容无法触发事件

    如果是新增 append 或者 html() 事件添加的内容,无法触发 click 事件, 在1.9 可以用live 事件来代替 1.9以后用 <div class="search-r ...

  10. 《DSP using MATLAB》示例Example7.2