leetcode463
public class Solution {
public int IslandPerimeter(int[,] grid) {
var row = grid.GetLength();//行数
var col = grid.GetLength();//列数
var count = ;
for (int i = ; i < row; i++)
{
for (int j = ; j < col; j++)
{
if (i == )
{
if (grid[i, j] == )
{
count++;
}
}
else
{
if (grid[i, j] != grid[i - , j])
{
count++;
}
}
if (i == row - && grid[i, j] == )
{
count++;
}
}
}
for (int j = ; j < col; j++)
{
for (int i = ; i < row; i++)
{
if (j == )
{
if (grid[i, j] == )
{
count++;
}
}
else
{
if (grid[i, j] != grid[i, j - ])
{
count++;
}
}
if (j == col - && grid[i, j] == )
{
count++;
}
}
}
//Console.WriteLine(count.ToString());
return count;
}
}
https://leetcode.com/problems/island-perimeter/#/description
leetcode463的更多相关文章
- Leetcode-463 Island Perimeter
#463. Island Perimeter You are given a map in form of a two-dimensional integer grid where 1 represe ...
- [Swift]LeetCode463. 岛屿的周长 | Island Perimeter
You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represen ...
- Leetcode463. Island Perimeter
题目 给定一个包含 0 和 1 的二维网格地图,其中 1 表示陆地 0 表示水域. 网格中的格子水平和垂直方向相连(对角线方向不相连).整个网格被水完全包围,但其中恰好有一个岛屿(或者说,一个或多个表 ...
- Leetcode463.Island Perimeter岛屿的周长
给定一个包含 0 和 1 的二维网格地图,其中 1 表示陆地 0 表示水域. 网格中的格子水平和垂直方向相连(对角线方向不相连).整个网格被水完全包围,但其中恰好有一个岛屿(或者说,一个或多个表示陆地 ...
随机推荐
- AJAX异步实现简单的瀑布流
传统瀑布流布局ul-li,需要先设定显示几列,每列是一个li,需要左浮动并指定宽度,li里面的布局也要先布局好,主要是要定宽,高度自动:然后通过ajax异步,从数据库中得到数据,遍历后将数据插入最矮的 ...
- 自制数据结构(容器)-java开发用的最多的ArrayList和HashMap
public class MyArrayList<E> { private int capacity = 10; private int size = 0; private E[] val ...
- MySQL Transaction--快照读和当前读
在MySQL读取数据时可以按照是否使用一致性非锁定读来分为快照读和当前读:1.快照读:MySQL使用MVCC (Multiversion Concurrency Control)机制来保证被读取到数据 ...
- goss docker-compose 集成使用
原理很简单,就是使用volume 进行数据共享, 并执行服务器状态校验 docker-compose 文件 version: "3" services: goss: image: ...
- Microsoft OWIN
About OWIN defines a standard interface between .NET web servers and web applications. The goal of t ...
- Nginx 下部署 HTTPS 与安全调优
什么是 HTTPS?# HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的 ...
- chrome和Firefox对p标签中单词换行的渲染(强制换行)
谷歌和火狐对p标签单词的渲染: 今天在p标签展示url链接中,由于有几个下划线拼接的单词特别长, 所以总有那么几行老是超出p标签的范围,然后设置了强制 换行,才得以解决. word-wrap : br ...
- Hyperic Sigar API 举例
Hyperic HQ 是什么? Hyperic HQ 是一个开源的(General Public License,GPL授权)IT资源管理框架,让用户使用统一的界面来管理各种不同的IT资源的管理,Hy ...
- Mac 配置多jdk 随意切换
1下载安装 jdk6:https://support.apple.com/kb/DL1572?locale=zh_CN 2配置环境变量 open .bash_profile export PATH=$ ...
- 用Keras搭建神经网络 简单模版(二)——Classifier分类(手写数字识别)
# -*- coding: utf-8 -*- import numpy as np np.random.seed(1337) #for reproducibility再现性 from keras.d ...