leetcode419
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的更多相关文章
- [Swift]LeetCode419. 甲板上的战舰 | Battleships in a Board
Given an 2D board, count how many battleships are in it. The battleships are represented with 'X's, ...
随机推荐
- GLSL 内建函数
内建函数基本上可以分为一下三类: (1)它们使用一些简便的方式提供必要的硬件功能,如材质贴图.这些函数单独通过着色器是无法模拟出来的. (2)它们展示了一些可以常简单的写入的繁琐操作(clamp, m ...
- RNG—随机数产生器
RNG 随机数产生器 RNG g_rng(12345); /********************************************************************** ...
- 第一次Sprint团队贡献分
201406114105 董婷婷 21 201406114157 容杰龙 22 201406114343 卓炜杰 ...
- 使用C#和Java发送邮件(转载)
using System.Net.Mail; using System.Net; public class EmailEntity { private MailMessage mm; /// < ...
- [转]console.time和console.timeEnd用法
console.time和console.timeEnd这两个方法可以用来让WEB开发人员测量一个javascript脚本程序执行消耗的时间.随着WEB应用越来越重要,JavaScript的执行性能也 ...
- guaua学习,工具专题
Preconditions 1,http://www.cnblogs.com/peida/p/Guava_Preconditions.html 1 .checkArgument(boolean) : ...
- erlang的格式化字符串
往pgsql里面写数据的时候,不能双引号,开始纠结的不行,用拼字符串的形式,后来发现可以格式化字符串,泪奔 data_format.erl -module(data_format). -export( ...
- golang的https服务器
先生成ssl证书 openssl genrsa - openssl req - 然后,大概这样 package main import ( "log" "net/http ...
- PdfPCell对齐方式,边框,边框颜色的使用 (转)
原文:http://www.cnblogs.com/LifelongLearning/archive/2011/06/22/2086802.html PdfPTable和PdfPCell对象,我们可以 ...
- Centos6-7安装Python3.5以及SSL的编译安装,识别https
Python3中无法导入ssl模块的解决办法 如果你发现在python3脚本运行过程中发现涉及到ssl模块都无法运行的情况下.那么需要进行如下步骤 第一步: yum install openssl o ...