zoukankan      html  css  js  c++  java
  • 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 shown in the figure.

    Rectangle Area

    Assume that the total area is never beyond the maximum possible value of int.

    Runtime: 40ms.

     1 class Solution {
     2 public:
     3     int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
     4         int s1 = (C - A) * (D - B);
     5         int s2 = (G - E) * (H - F);
     6         
     7         int x = min(C, G) <= max(E, A) ? 0 : min(C, G) - max(E, A);
     8         int y = min(D, H) <= max(B, F) ? 0 : min(D, H) - max(B, F); 
     9         
    10         return s1 + s2 - x * y;
    11     }
    12 };
  • 相关阅读:
    docker
    协程 gevent
    vue
    数据
    elk 配置
    iOS下架
    综合练习:词频统计
    组合数据类型综合练习
    Python基础综合练习
    熟悉常用的Linux操作
  • 原文地址:https://www.cnblogs.com/amazingzoe/p/4802502.html
Copyright © 2011-2022 走看看