4line 4ms Java Simple Solution


  • 0
    S
        public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
            return (int) computeAreaLong(A, B, C, D, E, F, G, H);
        }
        public long computeAreaLong(long A, long B, long C, long D, long E, long F, long G, long H) {
            long len = Math.min(C,G) - Math.max(A,E);
            long width = Math.min(D,H) - Math.max(B,F);
            return ((C - A) * (D - B) + (G - E) * (H - F) - ((len > 0)?len:0) * ((width > 0)?width:0));
        }

Log in to reply
 

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