Easy understanding concise java solution

  • 6
    public class Solution {
        public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
            int a = (C-A)*(D-B), b = (G-E)*(H-F);
            return a + b - overlap(A, C, E, G) * overlap(F, H, B, D);
        private int overlap(int a, int b, int c, int d) {
            if (b<=c || d<=a) { return 0; }  // not overlapping
            return Math.min(b, d) - Math.max(a, c);

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.