-
Notifications
You must be signed in to change notification settings - Fork 77
/
solution.cpp
85 lines (82 loc) · 1.6 KB
/
solution.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class Solution
{
public:
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H)
{
int width;
int height;
if( A<E )
{
if( C<=E )
{
width = 0;
}
else
{
if( C<=G )
{
width = C-E;
}
else
{
width = G-E;
}
}
}
else
{
if( A<G )
{
if( C<=G )
{
width = C-A;
}
else
{
width = G-A;
}
}
else
{
width = 0;
}
}
if( B<F )
{
if( D<=F )
{
height = 0;
}
else
{
if( D<=H )
{
height = D-F;
}
else
{
height = H-F;
}
}
}
else
{
if( B<H )
{
if( D<=H )
{
height = D-B;
}
else
{
height = H-B;
}
}
else
{
height = 0;
}
}
return ( (C-A)*(D-B) + (G-E)*(H-F) ) - width*height;
}
};