Rectangle Area

class Solution {
public:
    int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
    long total =  max((C-A),0) * max((D-B),0) +  max((G-E),0) * max((H-F),0) ;
    long comm;
    if(min(G,C) < max(E,A) || min(H,D) < max(F,B) )    //防止越界
        comm = 0;
    else
        comm  =  max(0,min(G,C)-max(E,A))  *  max(0,min(H,D)-max(F,B)) ;
   
    return total-comm;    
    }
    
};

  原题在此处  https://leetcode.com/problems/rectangle-area/

posted @ 2017-01-05 11:18  *桔子*  阅读(127)  评论(0编辑  收藏  举报