美文网首页
2019-02-01第七天

2019-02-01第七天

作者: 织雾呀 | 来源:发表于2019-02-01 22:09 被阅读0次

leetcode:

矩形重叠

非常暴力的解法:

class Solution {
    public boolean isRectangleOverlap(int[] rec1, int[] rec2) {
        return Math.max(rec1[0],rec2[0])<Math.min(rec1[2],rec2[2]) && Math.max(rec1[1],rec2[1])<Math.min(rec1[3],rec2[3]);
    }
}

就我自己的想法而言,判断有三种4种情况
比如:[0,0,2,2]可以拆分成
[0,0] [0,2] [2,0] [2,2]
以及:
[1,1,3,3]拆分成四个点
[1,1] [1,3] [3,1] [3,3]
所以要判断四次,没想到大佬的解法只判断了2次,牛批牛批

相关文章

网友评论

      本文标题:2019-02-01第七天

      本文链接:https://www.haomeiwen.com/subject/ajkjsqtx.html