Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 35bd155

Browse files
committed
463
1 parent 0b8c2d7 commit 35bd155

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ Success is like pregnancy, Everybody congratulates you but nobody knows how many
1111
## Linked List
1212
[Overview](http://www.cnblogs.com/Raising-Sun/p/5970662.html#3534606)
1313

14-
## Array
14+
## Array Medium
1515
| # | Title | Solution | Time | Space | Difficulty | Note|
1616
|-----|-------| -------- | ---- | ------|------------|-----|
1717
|3| [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/#/solutions) | [Python](./array/3.py) | _O(n)_| _O(n)_ | Medium | Hash table|
18+
|463| [Island Perimeter](https://leetcode.com/problems/island-perimeter/#/description) | [Python](./array/463.py) | _O(n^2)_| _O(1)_ | Medium | Google|
1819

1920
## Linked List Easy
2021
| # | Title | Solution | Time | Space | Difficulty |Tag| Note|

‎array/463.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
# Author: Yu Zhou
5+
# 463. Island Perimeter
6+
7+
# 将所有的1,也就是所有的格子乘以4,储存在一个res的变量
8+
# 检查这个格子的邻居,有则在变量减去2
9+
10+
class Solution(object):
11+
def islandPerimeter(self, grid):
12+
"""
13+
:type grid: List[List[int]]
14+
:rtype: int
15+
"""
16+
res = 0
17+
for i in xrange(len(grid)):
18+
for j in xrange(len(grid[i])):
19+
if grid[i][j] == 1:
20+
res += 4
21+
# Check Neighbor
22+
if i>0 and grid[i-1][j] == 1:
23+
res -= 2
24+
if j>0 and grid[i][j-1] == 1:
25+
res -= 2
26+
return res

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /