leetcode1034
class Solution:
def __init__(self):
self.V = list() def bfs(self,grid,color,rows,coloums,r,c,ocolor):
cur = [r,c]
if cur[0]-1 >=0 and self.V[cur[0]-1][cur[1]]==0 and grid[cur[0]-1][cur[1]]==ocolor:
grid[cur[0]-1][cur[1]] = color
self.V[cur[0]-1][cur[1]] = 1
self.bfs(grid,color,rows,coloums,cur[0]-1,cur[1],ocolor)
if cur[0]+1 <rows and self.V[cur[0]+1][cur[1]]==0 and grid[cur[0]+1][cur[1]] == ocolor:
grid[cur[0]+1][cur[1]] = color
self.V[cur[0]+1][cur[1]] = 1
self.bfs(grid,color,rows,coloums,cur[0]+1,cur[1],ocolor)
if cur[1]-1 >=0 and self.V[cur[0]][cur[1]-1]==0 and grid[cur[0]][cur[1]-1] == ocolor:
grid[cur[0]][cur[1]-1] = color
self.V[cur[0]][cur[1]-1] = 1
self.bfs(grid,color,rows,coloums,cur[0],cur[1]-1,ocolor)
if cur[1]+1 <coloums and self.V[cur[0]][cur[1]+1]==0 and grid[cur[0]][cur[1]+1]==ocolor:
grid[cur[0]][cur[1]+1] = color
self.V[cur[0]][cur[1]+1] = 1
self.bfs(grid,color,rows,coloums,cur[0],cur[1]+1,ocolor) def colorBorder(self, grid: 'List[List[int]]', r0: int, c0: int, color: int) -> 'List[List[int]]':
if grid[r0][c0] != color:
ocolor = grid[r0][c0]
rows = len(grid)
coloums = len(grid[0])
self.V = [[0 for c in range(coloums)] for r in range(rows)]
self.V[r0][c0] = 1
grid[r0][c0] = color
self.bfs(grid,color,rows,coloums,r0,c0,ocolor)
print(self.V)
for i in range(rows):
for j in range(coloums):
if i>0 and i<rows-1 and j>0 and j<coloums-1:
if self.V[i][j] == 1 and self.V[i-1][j]==1 and self.V[i+1][j]==1 and self.V[i][j-1]==1 and self.V[i][j+1]==1:
grid[i][j] = ocolor
return grid
这题是什么鬼玩意儿?是我打开方式不对么。。。
leetcode1034的更多相关文章
- [Swift]LeetCode1034.边框着色 | Coloring A Border
Given a 2-dimensional grid of integers, each value in the grid represents the color of the grid squa ...
随机推荐
- vs2017 asp.net 网站发布问题 (发布路径下含源码文件)
使用vs2010版本,网站发布后会自动将源码发不为.dll程序集,但vs2017需要进行设置,其他版本没有试过. vs2017网站发布: 1. 2. 这里给一个你想用的名字,之后它会出现在你的程序文件 ...
- Dubbo的三种连接方式
1.采用zookeeper作为注册中心 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns ...
- 修改应用进程open file值
本文用于记录java应用日志too many open files报错解决方法 操作系统:RHEL5.8 一.修改配置文件 1.vim /etc/security/limits.conf 加上:* s ...
- python padas 学习
import matplotlib from pandas import DataFrame import numpy as np import pandas as pd import MySQLdb ...
- Android Studio学习之 日志工具
Log.v() 低级日志 Log.d(' ',' ') debug调试信息 第一个参数tag,当前类名 第二个参数msg,打印具体内容 Log.i() info数据 Log.w() warn警 ...
- zabbix使用客户端和不使用客户端监控指定端口
监控指定端口也很简单,以监控181主机的22端口为例 点击已成功监控的181主机的监控项 点击创建监控项 使用客户端监控端口:选择键值net.tcp.listen[port],需要自己把port改成2 ...
- ansible常用模块入门
常用模块有以下几个 command copy shell crond yum service setup 1.command模块 ansible george -m command -a " ...
- Java String类和StringBuffer类的区别
1.String与StringBuffer的区别简单地说,就是一个变量和常量的关系.StringBuffer对象的内容可以修改:而String对象一旦产生后就不可以被修改,重新赋值其实是两个对象.St ...
- 通用唯一识别码UUID
UUID 概念:UUID 是 通用唯一识别码(Universally Unique Identifier)的缩写,目前最广泛应用的UUID,是微软公司的全局唯一标识符(GUID),而其他重要的应用,则 ...
- HTML与CSS:结构与表现
在HTML和CSS里存在着部分重复的功能,例如两者都可以设定一段文字的字体属性.既然如此,为啥还要CSS呢(至少,为啥CSS里存在着和HTML标签属性重复的东西呢)? 这是因为,HTML和CSS的用途 ...