Leetcode 223 Rectangle Area

求相交矩形的面积

 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 dx = max(A,E);
 5         int dy = max(B,F);
 6         int ux = min(C,G);
 7         int uy = min(D,H);
 8         if(ux>dx&&uy>dy){
 9             return (C-A)*(D-B)+(G-E)*(H-F) - (ux - dx) * (uy - dy);
10         }
11         else return (C-A)*(D-B)+(G-E)*(H-F) ;
12     }
13 };

 

posted @ 2016-03-12 22:29  Breeze0806  阅读(118)  评论(0编辑  收藏  举报