Skip to content

Commit 458f5f4

Browse files
committed
做了道题
1 parent ac0df90 commit 458f5f4

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

main.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,40 @@ def maxBottlesDrunk(self, numBottles: int, numExchange: int) -> int:
846846
empty -= numExchange
847847
numExchange += 1
848848
return drunked
849+
850+
def pacificAtlantic(self, heights: List[List[int]]) -> List[List[int]]:
851+
m = len(heights)
852+
n = len(heights[0])
853+
record = [[0] * n for _ in range(m)]
854+
855+
def dfs(x, y, mode=1):
856+
if -1 < x < m and -1 < y < n:
857+
if record[x][y] == mode or record[x][y] == 3:
858+
return
859+
else:
860+
record[x][y] += mode
861+
for delta in [[-1,0], [1,0], [0,1], [0,-1]]:
862+
tempx = x+delta[0]
863+
tempy = y+delta[1]
864+
if -1 < tempx < m and -1 < tempy < n:
865+
if heights[tempx][tempy] >= heights[x][y]:
866+
dfs(tempx, tempy, mode)
867+
for i in range(n):
868+
dfs(0, i, 1)
869+
dfs(m-1, i, 2)
870+
for i in range(m):
871+
dfs(i, 0, 1)
872+
dfs(i, n-1, 2)
873+
874+
accu = []
875+
for i in range(m):
876+
for j in range(n):
877+
if record[i][j] == 3:
878+
accu.append([i,j])
879+
return accu
880+
881+
882+
849883
# Your MovieRentingSystem object will be instantiated and called as such:
850884
# obj = MovieRentingSystem(n, entries)
851885
# param_1 = obj.search(movie)

0 commit comments

Comments
 (0)