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. hiho 1612

    emmmmm?A不了?90分是什么鬼 #include<cstdio> #include<cstdlib> #include<vector> #include< ...

  2. onerror="javascript:this.src='images/defaultUpload.png';"引发的死循环错误

    18:10:47.441 WARN o.s.web.servlet.PageNotFound:1101 - No mapping found for HTTP request with URI [/c ...

  3. threejs 世界坐标与屏幕坐标相互转换

    屏幕坐标转世界坐标: let pX = (screenPoint.x / this.scene.renderer.domElement.clientWidth) * 2 - 1; let pY = - ...

  4. 使用python处理selenium中的鼠标悬停问题

    # 导入selenium中的actionchains的方法 from selenium.webdriver.common.action_chains import ActionChains #识别需要 ...

  5. 《DSP using MATLAB》示例Example 8.12

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

  6. UVA11806 Cheerleaders

    题意 PDF 分析 如果要求是某行某列没有石子很好算,就一个组合数. 然后要求某行某列有,就用容斥原理就行了. 时间复杂度\(O(k^2 + 16T)\) 代码 #include<iostrea ...

  7. @contextmanager

    with的作用,类似try...finally...,提供一种上下文机制. 要应用with语句的类,其内部必须提供两个内置函数__enter__以及__exit__ ,   前者在主体代码执行前执行, ...

  8. 远程复制数据免登录 rsync 和 scp

    一.备用机上(用于存放备份的机器)  和 目标机上(需要备份的服务器 ,如 246) 都需要安装 :   yum install -y rsync 二.备用机上运行命令: -t rsa Generat ...

  9. 本地Office Project计划表同步到SharePoint2013任务列表的权限问题

    使用SharePoint做项目管理时,项目任务列表往往比较重要,通常使用任务列表体现项目计划,而这个任务列表经常会根据项目计划的变更而进行调整,但更多时候项目管理者会习惯在本地Project中维护这份 ...

  10. nginx学习与配置-安装与启动关闭管理

    nginx服务器的安装 安装准备: nginx依赖于pcre库,要先安装pcre yum install pcre pcre-devel cd /usr/local/src/ wget wget ht ...