码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode——Rectangle Area

时间:2015-06-24 01:57:19      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:

Description: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 area = (C-A)*(D-B) + (G-E)*(H-F);
        if (A >= G || B >= H || C <= E || D <= F) {
            return area;
        }
        int top = Math.min(D, H);
        int bottom = Math.max(B, F);
        int left = Math.max(A, E);
        int right = Math.min(C, G);
        return area - (top-bottom)*(right-left);
        
    }
}

 

LeetCode——Rectangle Area

标签:

原文地址:http://www.cnblogs.com/wxisme/p/4596664.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!