关闭

LeetCode 223 Rectangle Area

标签: leetcode几何
481人阅读 评论(0) 收藏 举报
分类:

Find the total area covered by two rectilinear rectangles in a 2D plane.

Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.

Rectangle Area
Assume that the total area is never beyond the maximum possible value of in.


题目链接:https://leetcode.com/problems/rectangle-area/

题目分析:主要是找重复,总的减去重复的即可

public class Solution {
    public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
        int area1 = (C - A) * (D - B);
        int area2 = (G - E) * (H - F);
        int buttom = Math.max(B, F);
        int top = Math.min(D, H);
        int right = Math.min(C, G);
        int left = Math.max(A, E);
        int both;
        if(buttom > top || left > right) {
            both = 0;
        }
        else {
            both = (top - buttom) * (right - left);
        }
        return area1 + area2 - both;
    }
}


0
0
查看评论

Leetcode_223_Rectangle Area

本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/46868363 Find the total area covered by two rectilinear rectangles i...
  • pistolove
  • pistolove
  • 2015-07-13 22:02
  • 987

【LeetCode-面试算法经典-Java实现】【223-Rectangle Area(矩形区域)】

【223-Rectangle Area(矩形区域)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】代码下载【https://github.com/Wang-Jun-Chao】原题  Find the total area covered by two rectilinear r...
  • DERRANTCM
  • DERRANTCM
  • 2015-08-29 06:39
  • 2709

LeetCode(223)_Rectangle Area

Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as ...
  • u011290316
  • u011290316
  • 2016-10-28 16:35
  • 93

[leetcode 223] Rectangle Area

Question: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top r...
  • Xiaohei00000
  • Xiaohei00000
  • 2015-11-19 12:33
  • 290

LeetCode 223 Rectangle Area

题目描述Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner a...
  • Yano_nankai
  • Yano_nankai
  • 2015-12-11 09:01
  • 276

leetCode #223 Rectangle Area

题目:求2个矩形加起来覆盖的面积 分析:主要要考虑重叠的判断。2个矩形若重叠,那么在水平方向它们左侧起点的最右端应该比右侧起点的最左端左,同时垂直方向,下侧起点的最上端比上侧的最下端要下。 答案: class Solution { public: int computeArea(int...
  • MarStarck
  • MarStarck
  • 2015-08-11 13:21
  • 219

【leetcode】【223】Rectangle Area

一、问题描述 Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom le...
  • xiaoliucool1314
  • xiaoliucool1314
  • 2016-03-17 10:11
  • 176

(LeetCode 223) Rectangle Area

Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as sh...
  • u014616233
  • u014616233
  • 2016-04-19 21:58
  • 441

leetcode 223: Rectangle Area

leetcode 223: Rectangle Area java c++ python
  • xudli
  • xudli
  • 2015-06-10 03:25
  • 8326

Rectangle Area - LeetCode 223

题目描述: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right cor...
  • bu_min
  • bu_min
  • 2015-06-08 22:04
  • 254
    个人资料
    • 访问:740060次
    • 积分:15305
    • 等级:
    • 排名:第880名
    • 原创:818篇
    • 转载:7篇
    • 译文:0篇
    • 评论:122条
    博客专栏