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的更多相关文章

  1. [Swift]LeetCode1034.边框着色 | Coloring A Border

    Given a 2-dimensional grid of integers, each value in the grid represents the color of the grid squa ...

随机推荐

  1. anki_vector SDK源码解析(教程)

    一:最近anki vector robot开放了Python SDK,我听到的第一时间就赶快上网查了查,先抛几个官网重要链接吧: Python编程API手册及环境搭建等: https://sdk-re ...

  2. CodeForce edu round 53 Div 2. D:Berland Fair

    D. Berland Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  3. Python爬虫初学者学习笔记(带注释)

    一,安装编程工具并进入编程界面 首先去https://www.continuum.io/downloads/网站下载Anaconda工具并安装;打开cmd,输入jupyter notebook并回车( ...

  4. test markdown to html

    软件版本 PHP 5.5.25 Yaf 2.3.2 域名 正式域名 gm.mgame.qihoo.net demo域名 demo.gm.mgame.qihoo.net 配置 配置目录 后台配置 con ...

  5. dataframe基础

    1 df[i]   其中i是0,1,2,3,...  此时选中的是dataframe的第i列 2 dataframe查看每一列是否有缺失值 temp = data.isnull().any() #列中 ...

  6. python获取机器信息脚本(网上寻找的)

    获取机器信息(待测试) # -*- coding: UTF-8 -*- import psutil import json import os import socket import struct ...

  7. TCP 选项RST

    1.RST介绍 RST表示reset复位,用于异常情况下关闭连接. 发送RST包关闭连接时,不必等缓冲区的包都发出去,直接就丢弃缓冲区中的包. 而接收端收到RST包后,也不必发送ACK包来确认. 2. ...

  8. WebService之客户端

    创建项目 File→New→Other→Web Services→Web Service Client中输入从服务端得到的wsdl链接: http://localhost:8080/WS_WebSer ...

  9. pll时钟延迟为问题

    pll时钟延迟为问题 这关系到pll的工作方式,如果pll内部使用的是鉴频器,则输入和输出将没有固定的相位差,就是每次锁定都锁定在某个相位,但每次都不一样.如果使用的是鉴相器,则输入和输出为0相位差. ...

  10. Plickers——教师拿手机、学生拿卡片,就可以完成即时全员互动!

    全员互动.立刻反馈.无设备添加.无能耗增加,风靡全球教育界,杭州师范大学硕士生导师杨俊锋教授推荐!老师拿手机,学生拿卡片就可以完成!      操作方法:      1.注册:登录www.plicke ...