Skip to content

Instantly share code, notes, and snippets.

@gcrfelix
Created August 19, 2015 13:36
Show Gist options
  • Save gcrfelix/bbd71a084a06c23f2384 to your computer and use it in GitHub Desktop.
Save gcrfelix/bbd71a084a06c23f2384 to your computer and use it in GitHub Desktop.
public class Solution {
public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int left = Math.max(A, E);
int right = Math.min(C, G);
int bottom = Math.max(B, F);
int top = Math.min(D, H);
int overlap = 0;
if(left < right && bottom < top) {
overlap = (right-left)*(top-bottom);
}
int area1 = (C-A)*(D-B);
int area2 = (G-E)*(H-F);
return area1 + area2 - overlap;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment