Skip to content

Commit

Permalink
add 1401
Browse files Browse the repository at this point in the history
  • Loading branch information
luliyucoordinate committed Apr 6, 2020
1 parent 780fecd commit cb59dd6
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -697,4 +697,5 @@ LeetCode
|1396|[Design Underground System](https://leetcode.com/problems/design-underground-system/)|c|[c++](./src/1396-Design-Underground-System/1396.cpp)|[python](./src/1396-Design-Underground-System/1396.py)|[go](./src/1396-Design-Underground-System/1396.go)|[js](./src/1396-Design-Underground-System/1396.js)|[java](./src/1396-Design-Underground-System/1396.java)|Medium|
|1397|[Find All Good Strings](https://leetcode.com/problems/find-all-good-strings/)|c|[c++](./src/1397-Find-All-Good-Strings/1397.cpp)|[python](./src/1397-Find-All-Good-Strings/1397.py)|[go](./src/1397-Find-All-Good-Strings/1397.go)|[js](./src/1397-Find-All-Good-Strings/1397.js)|[java](./src/1397-Find-All-Good-Strings/1397.java)|Hard|
|1399|[Count Largest Group](https://leetcode.com/problems/count-largest-group/)|c|[c++](./src/1399-Count-Largest-Group/1399.cpp)|[python](./src/1399-Count-Largest-Group/1399.py)|[go](./src/1399-Count-Largest-Group/1399.go)|[js](./src/1399-Count-Largest-Group/1399.js)|[java](./src/1399-Count-Largest-Group/1399.java)|Easy|
|1400|[Construct K Palindrome Strings](https://leetcode.com/problems/construct-k-palindrome-strings/)|c|[c++](./src/1400-Construct-K-Palindrome-Strings/1400.cpp)|[python](./src/1400-Construct-K-Palindrome-Strings/1400.py)|[go](./src/1400-Construct-K-Palindrome-Strings/1400.go)|[js](./src/1400-Construct-K-Palindrome-Strings/1400.js)|[java](./src/1400-Construct-K-Palindrome-Strings/1400.java)|Medium|
|1400|[Construct K Palindrome Strings](https://leetcode.com/problems/construct-k-palindrome-strings/)|c|[c++](./src/1400-Construct-K-Palindrome-Strings/1400.cpp)|[python](./src/1400-Construct-K-Palindrome-Strings/1400.py)|[go](./src/1400-Construct-K-Palindrome-Strings/1400.go)|[js](./src/1400-Construct-K-Palindrome-Strings/1400.js)|[java](./src/1400-Construct-K-Palindrome-Strings/1400.java)|Medium|
|1401|[Circle and Rectangle Overlapping](https://leetcode.com/problems/circle-and-rectangle-overlapping/)|c|[c++](./src/1401-Circle-and-Rectangle-Overlapping/1401.cpp)|[python](./src/1401-Circle-and-Rectangle-Overlapping/1401.py)|[go](./src/1401-Circle-and-Rectangle-Overlapping/1401.go)|[js](./src/1401-Circle-and-Rectangle-Overlapping/1401.js)|[java](./src/1401-Circle-and-Rectangle-Overlapping/1401.java)|Medium|
10 changes: 10 additions & 0 deletions src/1401-Circle-and-Rectangle-Overlapping/1401.cpp
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];
}
};
21 changes: 21 additions & 0 deletions src/1401-Circle-and-Rectangle-Overlapping/1401.go
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
}
9 changes: 9 additions & 0 deletions src/1401-Circle-and-Rectangle-Overlapping/1401.java
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];
}
}
7 changes: 7 additions & 0 deletions src/1401-Circle-and-Rectangle-Overlapping/1401.js
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];
};
7 changes: 7 additions & 0 deletions src/1401-Circle-and-Rectangle-Overlapping/1401.py
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)
6 changes: 3 additions & 3 deletions src/addProb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import os, bisect

# 题目名称
name = "Construct K Palindrome Strings"
ID = 1400
url = "https://leetcode.com/problems/construct-k-palindrome-strings/"
name = "Circle and Rectangle Overlapping"
ID = 1401
url = "https://leetcode.com/problems/circle-and-rectangle-overlapping/"
difficult = "Medium"
prog = ['c', 'cpp', 'py', 'go', 'js', 'java']

Expand Down

0 comments on commit cb59dd6

Please sign in to comment.