forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
780fecd
commit cb59dd6
Showing
7 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Solution { | ||
public: | ||
bool checkOverlap(int r, int xc, int yc, int x1, int y1, int x2, int y2) { | ||
int x = (x1 + x2) / 2, y = (y1 + y2) / 2; | ||
vector<int> h = {x2 - x, y2 - y}; | ||
vector<int> v = {abs(x - xc), abs(y - yc)}; | ||
vector<int> u = {max(v[0] - h[0], 0), max(v[1] - h[1], 0)}; | ||
return r * r >= u[0] * u[0] + u[1] * u[1]; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
func checkOverlap(r int, xc int, yc int, x1 int, y1 int, x2 int, y2 int) bool { | ||
x, y := (x1 + x2) / 2, (y1 + y2) / 2 | ||
h := []int{x2 - x, y2 - y} | ||
v := []int{abs(x - xc), abs(y - yc)} | ||
u := []int{max(v[0] - h[0], 0), max(v[1] - h[1], 0)} | ||
return r * r >= u[0] * u[0] + u[1] * u[1] | ||
} | ||
|
||
func max(a, b int) int { | ||
if a > b { | ||
return a | ||
} | ||
return b | ||
} | ||
|
||
func abs(a int) int { | ||
if a < 0 { | ||
return -a | ||
} | ||
return a | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Solution { | ||
public boolean checkOverlap(int r, int xc, int yc, int x1, int y1, int x2, int y2) { | ||
int x = (x1 + x2) / 2, y = (y1 + y2) / 2; | ||
int[] h = {x2 - x, y2 - y}; | ||
int[] v = {Math.abs(x - xc), Math.abs(y - yc)}; | ||
int[] u = {Math.max(v[0] - h[0], 0), Math.max(v[1] - h[1], 0)}; | ||
return r * r >= u[0] * u[0] + u[1] * u[1]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var checkOverlap = function(r, xc, yc, x1, y1, x2, y2) { | ||
let x = (x1 + x2) / 2, y = (y1 + y2) / 2; | ||
let h = [x2 - x, y2 - y]; | ||
let v = [Math.abs(x - xc), Math.abs(y - yc)]; | ||
let u = [Math.max(v[0] - h[0], 0), Math.max(v[1] - h[1], 0)]; | ||
return r * r >= u[0] * u[0] + u[1] * u[1]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Solution: | ||
def checkOverlap(self, r: int, xc: int, yc: int, x1: int, y1: int, x2: int, y2: int) -> bool: | ||
x, y = (x1 + x2) / 2, (y1 + y2) / 2 | ||
h = [x2 - x, y2 - y] | ||
v = [abs(x - xc), abs(y - yc)] | ||
u = [max(v[0] - h[0], 0), max(v[1] - h[1], 0)] | ||
return r**2 >= (u[0]**2 + u[1]**2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters