日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

文巾解题 733. 图像渲染

發布時間:2025/4/5 编程问答 11 豆豆
生活随笔 收集整理的這篇文章主要介紹了 文巾解题 733. 图像渲染 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1 題目描述

2 解題思路

注意一點,如果第一個要渲染的點,顏色和要渲染成的顏色是一樣的,那么我們直接返回。不然的話會死循環。

2.1 廣度優先遍歷?

廣搜是使用隊列來實現的

class Solution:def floodFill(self, image: List[List[int]], sr: int, sc: int, newColor: int) -> List[List[int]]:row=len(image)column=len(image[0])color=image[sr][sc]if(image[sr][sc]==newColor):return image #特判不需要任何修改的情況image[sr][sc]=newColorlst=[(sr,sc)]while(lst):print(lst)tmp_x,tmp_y=lst.pop(0)for x,y in [(tmp_x-1,tmp_y),(tmp_x+1,tmp_y),(tmp_x,tmp_y-1),(tmp_x,tmp_y+1)]:if(x>=0 and x<row and y>=0 and y<column):if(image[x][y]==color):image[x][y]=newColorlst.append((x,y))return(image)

2.2 深度優先遍歷

深搜是使用遞歸來實現的

class Solution:def floodFill(self, image: List[List[int]], sr: int, sc: int, newColor: int) -> List[List[int]]:row=len(image)column=len(image[0])color=image[sr][sc]if(image[sr][sc]==newColor):return image #特判不需要渲染的情況image[sr][sc]=newColordef dfs(x,y):for (i,j) in [(x-1,y),(x+1,y),(x,y-1),(x,y+1)]:if(i>=0 and i < row and j>=0 and j<column):if(image[i][j]==color):image[i][j]=newColordfs(i,j)dfs(sr,sc)return image

總結

以上是生活随笔為你收集整理的文巾解题 733. 图像渲染的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。