-
Notifications
You must be signed in to change notification settings - Fork 0
/
bomb-enemy.py
42 lines (42 loc) · 1.33 KB
/
bomb-enemy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Solution:
def maxKilledEnemies(self, grid: List[List[str]]) -> int:
if not grid:
return 0
rows, cols = len(grid), len(grid[0])
count = [[0 for _ in range(cols)] for _ in range(rows)]
for i in range(rows):
c = 0
for j in range(cols):
if grid[i][j] == "W":
c = 0
elif grid[i][j] == "E":
c += 1
count[i][j] += c
for i in range(rows):
c = 0
for j in range(cols - 1, -1, -1):
if grid[i][j] == "W":
c = 0
elif grid[i][j] == "E":
c += 1
count[i][j] += c
for j in range(cols):
c = 0
for i in range(rows):
if grid[i][j] == "W":
c = 0
elif grid[i][j] == "E":
c += 1
count[i][j] += c
ans = 0
for j in range(cols):
c = 0
for i in range(rows - 1, -1, -1):
if grid[i][j] == "W":
c = 0
elif grid[i][j] == "E":
c += 1
count[i][j] += c
if grid[i][j] == "0":
ans = max(ans, count[i][j])
return ans