-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathq0835.py
More file actions
40 lines (31 loc) · 1.17 KB
/
q0835.py
File metadata and controls
40 lines (31 loc) · 1.17 KB
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
#!/usr/bin/python3
from typing import List
from copy import deepcopy
class Solution:
def largestOverlap(self, A: List[List[int]], B: List[List[int]]) -> int:
flag_list = list()
len_row = len(B)
len_col = len(B[0])
for i in range(len_row):
for j in range(len_col):
if B[i][j] == 1:
flag_list.append([i, j])
def countOverLapNum(target: List[List[int]], flags: List[List[int]], offset_row: int, offset_col: int, _len_row: int, _len_col: int) -> int:
local_count = 0
for pair in flags:
row = pair[0] + offset_row
col = pair[1] + offset_col
if 0 <= row < _len_row and 0 <= col < _len_col and target[row][col] == 1:
local_count += 1
return local_count
result = 0
i = -len_row + 1
while i < len_row:
j = -len_col + 1
while j < len_col:
count = countOverLapNum(A, flag_list, i, j, len_row, len_col)
if result < count:
result = count
j += 1
i += 1
return result