题目如下:

解题思路:抛开移动的过程只看移动完成的结果,记图片左上角为顶点,正方形边长为board,要使得两个图片要有重叠,那么一定其中一张图片的顶点和另外一张图片的某一个点重合。假设图片A的顶点A(0,0)和图片B的其中一个点B(x,y)重合,那么A与B重合的区域就是A(0,0) -> A(board-x,board-y) ,B(x,y) -> B(board,board) ,计算A与B的重合部分中每个点都为1的个数就是A(0,0)与B(x,y)重合时候能得到的overlap。最后计算出B中所有点与A(0,0)重合和A中所有点与B(0,0)重合的overlap,求出最大值即可。

代码如下:

class Solution(object):
def getOverlap(self,a,b,ax,ay):
count = 0
for i in range(ax,len(a)):
for j in range(ay,len(a[i])):
if a[i][j] == b[i-ax][j-ay] == 1:
count += 1
return count def largestOverlap(self, A, B):
"""
:type A: List[List[int]]
:type B: List[List[int]]
:rtype: int
"""
res = 0
board = len(A)
for i in range(board):
for j in range(board):
res = max(res,self.getOverlap(A,B,i,j))
res = max(res, self.getOverlap(B, A, i, j))
return res

【leetcode】835. Image Overlap的更多相关文章

  1. 【LeetCode】835. Image Overlap 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  2. 【LeetCode】836. Rectangle Overlap 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/rectangle ...

  3. 【LeetCode】435. Non-overlapping Intervals 解题报告(Python)

    [LeetCode]435. Non-overlapping Intervals 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemi ...

  4. 【LeetCode】833. Find And Replace in String 解题报告(Python)

    [LeetCode]833. Find And Replace in String 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu ...

  5. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  6. 【Leetcode】Pascal's Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  7. 53. Maximum Subarray【leetcode】

    53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...

  8. 27. Remove Element【leetcode】

    27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...

  9. 【刷题】【LeetCode】007-整数反转-easy

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...

随机推荐

  1. note2

  2. Mac OS 10.15系统入门教程 系统语言输入法详解

    对于一些Mac新手来说呢还不知道偏好设置到底是什么?有什么用处?其实Mac系统内的几乎所有的系统相关的设置都会在系统偏好设置内出现. 切换系统语⾔在语言与地区设置中拖拽左侧的语言条目就可以切换系统的语 ...

  3. Linux任务计划at

    Linux任务计划at 一Linux任务计划介绍 Linux任务计划.周期性任务执行at:未来的某时间点执行一次任务batch:系统自行选择空闲时间去执行此处指定的任务cron:周期性运行某任务 二a ...

  4. Angular JS - 3 - Angular JS 双向数据绑定

    一 .数据绑定 1. 数据绑定: 数据从一个地方A转移(传递)到另一个地方B, 而且这个操作由框架来完成2. 双向数据绑定: 数据可以从View(视图层)流向Model(模型,也就是数据), 也可以从 ...

  5. HDU 6121 Build a tree —— 2017 Multi-University Training 7

    HazelFan wants to build a rooted tree. The tree has nn nodes labeled 0 to n−1, and the father of the ...

  6. spring boot 修改banner

    在resources目录下新建一个banner.txt,里面添加要显示的内容,如: ////////////////////////////////////////////////////////// ...

  7. vector代替数组

    vector代替数组 1.声明一个int向量以替代一维的数组:vector <int> a;(等于声明了一个int数组a[],大小没有指定,可以动态的向里面添加删除). 2.用vector ...

  8. ES6 Generator使用

    // generator介绍: function* hello() { console.log("hello world") } hello();//没有执行 // 直接调用hel ...

  9. 通过export方式导出,在导入时要加{ },export default则不需要

    怎么就是记不住呢?? 通过export方式导出,在导入时要加{ },export default则不需要

  10. Linux系统CPU占用率较高问题排查思路

    作为 Linux 运维工程师,在日常工作中我们会遇到 Linux服务器上出现CPU负载达到100%居高不下的情况,如果CPU 持续跑高,则会影响业务系统的正常运行,带来企业损失. 很多运维的同学遇到这 ...