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 ...
随机推荐
- vue使用axios 时 后台接收不到数据
后台用django 时,默认接收的数据格式为formdata ,前端如果传了其他格式会出现后台收不到参数的情况. 前端参数转 fromdata 代码如下 let formData = new Form ...
- dubbo 中文官网
根大家分享一下:dubbo的中文官网迁移到了githup上地址:https://dubbo.gitbooks.io/dubbo-user-book/content/preface/background ...
- day02 格式化字符串
字符格式化2019-04-01 方法一 通过f + {} 格式化字符串 name = input("Name: ")age = input("Age:")sco ...
- Go 变量声明后若不赋值,各类型默认值
Go 变量声明后若不赋值,各类型默认值(数字类型默认为 0,其他类型为 nil): 数据类型 默认值 bool false string 空字符串 int 0 float32 0 float64 0 ...
- a标签通过浏览器下载远程图片
<a href="http://fooku.oss-cn-hongkong.aliyuncs.com/image/store/2nblHVyB6cWyBI7Aq2SEp6aZRBlui ...
- 线程中AutoResetEvent与ManualResetEvent的区别
线程之间的通信是通过发信号来进行沟通的.. ManualResetEvent发送Set信后后,需要手动Reset恢复初始状态.而对于AutoResetEvent来说,当发送完毕Set信号后,会自动Re ...
- 黄聪:Windows2012-IIS8安装SSL证书
开始菜单->右上角搜索按钮-> mmc 弹出窗口 关闭控制台会提示保存 打开iis新建站点,为了兼容不支持sni的浏览器,绑定默认https
- multipart/form-data和application/x-www-form-urlencoded区别
FORM元素的enctype属性指定了表单数据向服务器提交时所采用的编码类型.例如: application/x-www-form-urlencoded: 窗体数据被编码为名称/值对.这是标准的编码格 ...
- 2018-2019-2 20175227张雪莹《Java程序设计》 实验二《Java面向对象程序设计》
2018-2019-2 20175227张雪莹<Java程序设计> 实验二<Java面向对象程序设计> 实验报告封面 课程:Java程序设计 班级:1752班 姓名:张雪莹 学 ...
- python_项目_ATM和购物商城的程序
1 需求 模拟实现一个ATM + 购物商城程序 额度15000或自定义 实现购物商城,买东西加入购物车,调用信用卡接口结账 可以提现,手续费5% 支持多账户登录 支持账户间转账 记录每月日常消费流水 ...