Skip to content

Commit c8c389e

Browse files
committed
Create rectangle-area.cpp
1 parent f5de229 commit c8c389e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

C++/rectangle-area.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Time: O(1)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
7+
return (D - B) * (C - A) +
8+
(G - E) * (H - F) -
9+
max(0, (min(C, G) - max(A, E))) *
10+
max(0, (min(D, H) - max(B, F)));
11+
}
12+
};

0 commit comments

Comments
 (0)