File tree 2 files changed +30
-3
lines changed
2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change 1
1
# LeetCode Algorithms
2
2
3
- ![ problems-solved] ( https://img.shields.io/badge/Problems%20Solved-194 /2081-1f425f.svg )
4
- ![ problems-solved-java] ( https://img.shields.io/badge/Java-194 /2081-1abc9c.svg )
3
+ ![ problems-solved] ( https://img.shields.io/badge/Problems%20Solved-195 /2081-1f425f.svg )
4
+ ![ problems-solved-java] ( https://img.shields.io/badge/Java-195 /2081-1abc9c.svg )
5
5
![ problems-solved-python] ( https://img.shields.io/badge/Python-186/2081-1abc9c.svg )
6
6
[ ![ PRs Welcome] ( https://img.shields.io/badge/PRs-welcome-brightgreen.svg )] ( CONTRIBUTING.md )
7
7
[ ![ cp] ( https://img.shields.io/badge/also%20see-Competitve%20Programming-1f72ff.svg )] ( https://github.com/anishLearnsToCode/competitive-programming )
225
225
| 824 | [ Goat Latin] ( https://leetcode.com/problems/goat-latin ) | [ ![ Java] ( assets/java.png )] ( src/GoatLatin.java ) |
226
226
| 830 | [ Positions of Large Groups] ( https://leetcode.com/problems/positions-of-large-groups ) | [ ![ Java] ( assets/java.png )] ( src/PositionsOfLargeGroups.java ) |
227
227
| 832 | [ Flipping an Image] ( https://leetcode.com/problems/flipping-an-image ) | [ ![ Java] ( assets/java.png )] ( src/FlippingAnImage.java ) |
228
- | 836 | [ Rectangle Overlap] ( https://leetcode.com/problems/rectangle-overlap ) | |
228
+ | 836 | [ Rectangle Overlap] ( https://leetcode.com/problems/rectangle-overlap ) | [ ![ Java ] ( assets/java.png )] ( src/RectangleOverlap.java ) |
229
229
| 840 | [ Magic Squares in Grid] ( https://leetcode.com/problems/magic-squares-in-grid ) | |
230
230
| 844 | [ Backspace String Compare] ( https://leetcode.com/problems/backspace-string-compare ) | |
231
231
| 849 | [ Maximize Distance to Closest Person] ( https://leetcode.com/problems/maximize-distance-to-closest-person ) | |
Original file line number Diff line number Diff line change
1
+ public class RectangleOverlap {
2
+ public boolean isRectangleOverlap (int [] rec1 , int [] rec2 ) {
3
+ Rectangle rectangle1 = new Rectangle (rec1 );
4
+ Rectangle rectangle2 = new Rectangle (rec2 );
5
+ return hasXIntersection (rectangle1 , rectangle2 ) && hasYIntersection (rectangle1 , rectangle2 );
6
+ }
7
+
8
+ private boolean hasXIntersection (Rectangle rec1 , Rectangle rec2 ) {
9
+ return (rec1 .x1 <= rec2 .x1 && rec2 .x1 < rec1 .x2 )
10
+ || (rec2 .x1 < rec1 .x1 && rec1 .x1 < rec2 .x2 );
11
+ }
12
+
13
+ private boolean hasYIntersection (Rectangle rec1 , Rectangle rec2 ) {
14
+ return (rec1 .y1 <= rec2 .y1 && rec2 .y1 < rec1 .y2 )
15
+ || (rec2 .y1 < rec1 .y1 && rec1 .y1 < rec2 .y2 );
16
+ }
17
+
18
+ private static class Rectangle {
19
+ private final int x1 , x2 , y1 , y2 ;
20
+ Rectangle (int [] points ) {
21
+ this .x1 = points [0 ];
22
+ this .y1 = points [1 ];
23
+ this .x2 = points [2 ];
24
+ this .y2 = points [3 ];
25
+ }
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments