Skip to content

Commit 65fcec7

Browse files
rectangle area
1 parent 648c5ca commit 65fcec7

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

‎EASY/src/easy/RectangleArea.java

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package easy;
2+
3+
public class RectangleArea {
4+
5+
public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
6+
int areaA = (C-A)*(D-B);
7+
int areaB = (G-E)*(H-F);
8+
9+
int top = Math.min(D, H);
10+
int bottom = Math.max(B, F);
11+
int left = Math.max(A, E);
12+
int right = Math.min(C, G);
13+
14+
int overlap = 0;
15+
if(top > bottom && right > left) overlap = (top - bottom)*(right - left);
16+
return areaA + areaB - overlap;
17+
}
18+
19+
}

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
|278|[First Bad Version](https://leetcode.com/problems/first-bad-version/)|[Solution](../../blob/master/EASY/src/easy/FirstBadVersion.java)| O(logn)|O(1) | Easy| Binary Search
2626
|273|[Integer to English Words](https://leetcode.com/problems/integer-to-english-words/)|[Solution]|
2727
|257|[Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths/)|[Solution](../../blob/master/EASY/src/easy/BinaryTreePaths.java) | O(n*h) | O(h) | DFS/Recursion
28+
|223|[Rectangle Area](https://leetcode.com/problems/rectangle-area/)|[Solution](../../blob/master/EASY/src/easy/RectangleArea.java)| O(1)|O(1) | Easy|
2829
|209|[Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum/)|[Solution](../../blob/master/MEDIUM/src/medium/MinimumSizeSubarraySum.java)| O(n)|O(1) | Medium|
2930
|206|[Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/)|[Solution](../../blob/master/EASY/src/easy/ReverseLinkedList.java)| O(n)|O(1) | Easy
3031
|205|[Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings/)|[Solution](../../blob/master/EASY/src/easy/IsomorphicStrings.java)| O(n)|O(1) | Easy

0 commit comments

Comments
 (0)