Hi, this is Shunchi!

  • Home

  • Tags0

  • Archives267

  • Categories0

  • Curricula

  • DSA

  • LeetCode_Notes

  • Interviews

  • General

  • Resume

223. Rectangle Area

Posted on 2020-06-09 | Edited on 2021-01-22

LeetCode

Explanation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int areaRectA=(C-A)*(D-B);
int areaRectB=(G-E)*(H-F);

int left=Math.max(A,E);
int right=Math.min(C,G);
int top=Math.min(D,H);
int bottom=Math.max(B,F);

// If overlap
int overlap=0;
if(left<right&&bottom<top) overlap=(right-left)*(top-bottom);

return areaRectA+areaRectB-overlap;
}
}

<1…176177178…267>
ShunchiZhou

ShunchiZhou

267 posts
RSS
GitHub E-Mail Gitbook Linkedin
© 2024 ShunchiZhou
Powered by Hexo v5.4.0
|
0%