mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-12 18:08:38 +08:00
routine
This commit is contained in:
29
25/11/3531.cpp
Normal file
29
25/11/3531.cpp
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
int countCoveredBuildings(int n, std::vector<std::vector<int>>& buildings) {
|
||||||
|
std::vector<int> maxX(n + 1);
|
||||||
|
std::vector<int> minX(n + 1, n + 1);
|
||||||
|
std::vector<int> maxY(n + 1);
|
||||||
|
std::vector<int> minY(n + 1, n + 1);
|
||||||
|
|
||||||
|
for (auto &p : buildings) {
|
||||||
|
int x = p[0], y = p[1];
|
||||||
|
maxX[y] = std::max(maxX[y], x);
|
||||||
|
minX[y] = std::min(minX[y], x);
|
||||||
|
maxY[x] = std::max(maxY[x], y);
|
||||||
|
minY[x] = std::min(minY[x], y);
|
||||||
|
}
|
||||||
|
|
||||||
|
int res = 0;
|
||||||
|
for (auto &p : buildings) {
|
||||||
|
int x = p[0], y = p[1];
|
||||||
|
if (x > minX[y] && x < maxX[y] && y > minY[x] && y < maxY[x]) {
|
||||||
|
res++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
};
|
||||||
25
25/11/go/3531.go
Normal file
25
25/11/go/3531.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package L12
|
||||||
|
|
||||||
|
import "math"
|
||||||
|
|
||||||
|
func countCoveredBuildings(n int, buildings [][]int) int {
|
||||||
|
ans, minX, maxX, minY, maxY := 0, make([]int, n+1), make([]int, n+1), make([]int, n+1), make([]int, n+1)
|
||||||
|
for i := range minX {
|
||||||
|
minX[i], minY[i], maxX[i], maxY[i] = math.MaxInt, math.MaxInt, math.MinInt, math.MinInt
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, building := range buildings {
|
||||||
|
x := building[0]
|
||||||
|
y := building[1]
|
||||||
|
minX[y], maxX[y], minY[x], maxY[x] = min(minX[y], x), max(maxX[y], x), min(minY[x], y), max(maxY[x], y)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, building := range buildings {
|
||||||
|
x := building[0]
|
||||||
|
y := building[1]
|
||||||
|
if x < maxX[y] && x > minX[y] && y < maxY[x] && y > minY[x] {
|
||||||
|
ans++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ans
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user