标签:
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); } }
标签:
原文地址:http://www.cnblogs.com/wxisme/p/4596664.html