Skip to content

Commit

Permalink
Create rectangle-overlap.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 authored May 21, 2018
1 parent 37e84b1 commit 55943f0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions C++/rectangle-overlap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Time: O(1)
// Space: O(1)

class Solution {
public:
bool isRectangleOverlap(vector<int>& rec1, vector<int>& rec2) {
return (intersect(rec1[0], rec1[2], rec2[0], rec2[2]) &&
intersect(rec1[1], rec1[3], rec2[1], rec2[3]));
}

private:
bool intersect(int p_left, int p_right, int q_left, int q_right) {
return max(p_left, q_left) < min(p_right, q_right);
}
};

0 comments on commit 55943f0

Please sign in to comment.