Wrong test case


  • 0
    H

    Submission Result: Wrong Answer More Details

    Input:
    -2
    -2
    2
    2
    3
    3
    4
    4
    Output:
    0
    Expected:
    17

    The input has no overlapping region, so the answer should be 0, but the system return 17.

    P.S my answer is:
    public class Solution {
    public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {

        if(A == C && B == D) {
            return (G-E)*(H-F);
        } 
        if(G == E && H == F) {
            return (C-A)*(D-B);
        }
        
        int lx = Math.max(A, E);
        int rx = Math.min(C, G);
        int uy = Math.min(D, H);
        int by = Math.max(F, B);
        if(lx >= rx || uy <= by) {
            return 0;
        } else {
            return (rx - lx) * (uy - by);
        }
    }
    

    }


  • 0
    P

    It's the total area of the two rectangles instead of the overlapping area...


  • 0
    H

    I see. Thank you very much!


  • 0
    J

    You misunderstand the problem. This problem asks you to calculate the TOTAL area covered by these two regions instead of the overlapped area.


Log in to reply
 

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