Skip to content

Commit 1cf356c

Browse files
committed
update: 添加问题“3531.统计被覆盖的建筑”的代码和题解 (#1218)
3531: AC.cpp+py+go+java+rust (#1217) cpp(1e5version) - AC,27.12%,27.12% cpp - AC,55.93%,55.93% py - AC,60.46%,86.05% go - AC,44.44%,33.33% rust - AC,50.00%,-% 是不是这道题通过者还比较少(看超越百分比有感) Signed-off-by: LetMeFly666 <[email protected]>
1 parent 3423ebe commit 1cf356c

12 files changed

+498
-4
lines changed

.commitmsg

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
3531: AC.cpp+py+go+java+rust (#1217)
2+
3+
cpp(1e5version) - AC,27.12%,27.12%
4+
cpp - AC,55.93%,55.93%
5+
py - AC,60.46%,86.05%
6+
go - AC,44.44%,33.33%
7+
rust - AC,50.00%,-%
8+
9+
是不是这道题通过者还比较少(看超越百分比有感)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-12-11 13:14:46
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-11 13:23:40
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
int countCoveredBuildings(int n, vector<vector<int>>& buildings) {
14+
vector<int> xm(100001, 100001), xM(100001), ym(100001, 100001), yM(100001);
15+
for (vector<int>& building : buildings) {
16+
int x = building[0], y = building[1];
17+
xm[x] = min(xm[x], y);
18+
xM[x] = max(xM[x], y);
19+
ym[y] = min(ym[y], x);
20+
yM[y] = max(yM[y], x);
21+
}
22+
int ans = 0;
23+
for (vector<int>& building : buildings) {
24+
int x = building[0], y = building[1];
25+
ans += xm[x] < y && y < xM[x] && ym[y] < x && x < yM[y];
26+
}
27+
return ans;
28+
}
29+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-12-11 13:14:46
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-11 13:35:38
6+
*/
7+
package main
8+
9+
func countCoveredBuildings(n int, buildings [][]int) (ans int) {
10+
n++
11+
xm := make([]int, n)
12+
xM := make([]int, n)
13+
ym := make([]int, n)
14+
yM := make([]int, n)
15+
for i := range xm {
16+
xm[i] = n
17+
ym[i] = n
18+
}
19+
20+
for _, building := range buildings {
21+
x, y := building[0], building[1]
22+
xm[x] = min(xm[x], y)
23+
xM[x] = max(xM[x], y)
24+
ym[y] = min(ym[y], x)
25+
yM[y] = max(yM[y], x)
26+
}
27+
28+
for _, building := range buildings {
29+
x, y := building[0], building[1]
30+
if xm[x] < y && y < xM[x] && ym[y] < x && x < yM[y] {
31+
ans++
32+
}
33+
}
34+
return
35+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-12-11 13:14:46
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-11 13:40:24
6+
*/
7+
import java.util.Arrays;
8+
9+
class Solution {
10+
public int countCoveredBuildings(int n, int[][] buildings) {
11+
n++;
12+
int[] xm = new int[n];
13+
int[] xM = new int[n];
14+
int[] ym = new int[n];
15+
int[] yM = new int[n];
16+
Arrays.fill(xm, n);
17+
Arrays.fill(ym, n);
18+
19+
for (int[] building : buildings) {
20+
int x = building[0], y = building[1];
21+
xm[x] = Math.min(xm[x], y);
22+
xM[x] = Math.max(xM[x], y);
23+
ym[y] = Math.min(ym[y], x);
24+
yM[y] = Math.max(yM[y], x);
25+
}
26+
27+
int ans = 0;
28+
for (int[] building : buildings) {
29+
int x = building[0], y = building[1];
30+
if (xm[x] < y && y < xM[x] && ym[y] < x && x < yM[y]) {
31+
ans++;
32+
}
33+
}
34+
return ans;
35+
}
36+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-12-11 13:14:46
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-12-11 13:27:34
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def countCoveredBuildings(self, n: int, buildings: List[List[int]]) -> int:
11+
n += 1
12+
xm = [n] * n
13+
xM = [0] * n
14+
ym = [n] * n
15+
yM = [0] * n
16+
for x, y in buildings:
17+
xm[x] = min(xm[x], y)
18+
xM[x] = max(xM[x], y)
19+
ym[y] = min(ym[y], x)
20+
yM[y] = max(yM[y], x)
21+
ans = 0
22+
for x, y in buildings:
23+
ans += xm[x] < y < xM[x] and ym[y] < x < yM[y]
24+
return ans
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-12-11 13:14:46
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-11 13:48:09
6+
*/
7+
impl Solution {
8+
pub fn count_covered_buildings(mut n: i32, buildings: Vec<Vec<i32>>) -> i32 {
9+
n += 1;
10+
let mut xm: Vec<i32> = vec![n; n as usize];
11+
let mut xM: Vec<i32> = vec![0; n as usize];
12+
let mut ym: Vec<i32> = vec![n; n as usize];
13+
let mut yM: Vec<i32> = vec![0; n as usize];
14+
15+
for building in buildings.iter() {
16+
let x: i32 = building[0];
17+
let y: i32 = building[1];
18+
xm[x as usize] = xm[x as usize].min(y);
19+
xM[x as usize] = xM[x as usize].max(y);
20+
ym[y as usize] = ym[y as usize].min(x);
21+
yM[y as usize] = yM[y as usize].max(x);
22+
}
23+
24+
let mut ans: i32 = 0;
25+
for building in buildings.iter() {
26+
let x: i32 = building[0];
27+
let y: i32 = building[1];
28+
if xm[x as usize] < y && y < xM[x as usize] && ym[y as usize] < x && x < yM[y as usize] {
29+
ans += 1;
30+
}
31+
}
32+
ans
33+
}
34+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-12-11 13:14:46
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-12-11 13:23:40
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
int countCoveredBuildings(int n, vector<vector<int>>& buildings) {
14+
n++;
15+
vector<int> xm(n, n), xM(n), ym(n, n), yM(n);
16+
for (vector<int>& building : buildings) {
17+
int x = building[0], y = building[1];
18+
xm[x] = min(xm[x], y);
19+
xM[x] = max(xM[x], y);
20+
ym[y] = min(ym[y], x);
21+
yM[y] = max(yM[y], x);
22+
}
23+
int ans = 0;
24+
for (vector<int>& building : buildings) {
25+
int x = building[0], y = building[1];
26+
ans += xm[x] < y && y < xM[x] && ym[y] < x && x < yM[y];
27+
}
28+
return ans;
29+
}
30+
};

Codes/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
* @LastEditTime: 2025-11-01 22:18:35
66
*/
77
pub struct Solution;
8-
include!("3577-count-the-number-of-computer-unlocking-permutations.rs"); // 这个fileName是会被脚本替换掉的
8+
include!("3531-count-covered-buildings.rs"); // 这个fileName是会被脚本替换掉的

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,7 @@
10521052
|3494.酿造药水需要的最少总时间|中等|<a href="https://leetcode.cn/problems/find-the-minimum-amount-of-time-to-brew-potions/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/10/09/LeetCode%203494.%E9%85%BF%E9%80%A0%E8%8D%AF%E6%B0%B4%E9%9C%80%E8%A6%81%E7%9A%84%E6%9C%80%E5%B0%91%E6%80%BB%E6%97%B6%E9%97%B4/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/152847907" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-the-minimum-amount-of-time-to-brew-potions/solutions/3801656/letmefly-3494niang-zao-yao-shui-xu-yao-d-bjxv/" target="_blank">LeetCode题解</a>|
10531053
|3508.设计路由器|中等|<a href="https://leetcode.cn/problems/implement-router/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/09/20/LeetCode%203508.%E8%AE%BE%E8%AE%A1%E8%B7%AF%E7%94%B1%E5%99%A8/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/151901838" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/implement-router/solutions/3787451/letmefly-3508she-ji-lu-you-qi-stltao-stl-ehkf/" target="_blank">LeetCode题解</a>|
10541054
|3516.找到最近的人|简单|<a href="https://leetcode.cn/problems/find-closest-person/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/09/04/LeetCode%203516.%E6%89%BE%E5%88%B0%E6%9C%80%E8%BF%91%E7%9A%84%E4%BA%BA/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/151184074" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-closest-person/solutions/3772009/letmefly-3516zhao-dao-zui-jin-de-ren-ji-8rlbz/" target="_blank">LeetCode题解</a>|
1055+
|3531.统计被覆盖的建筑|中等|<a href="https://leetcode.cn/problems/count-covered-buildings/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/12/11/LeetCode%203531.%E7%BB%9F%E8%AE%A1%E8%A2%AB%E8%A6%86%E7%9B%96%E7%9A%84%E5%BB%BA%E7%AD%91/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/155824933" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-covered-buildings/solutions/3854864/letmefly-3531tong-ji-bei-fu-gai-de-jian-9kgng/" target="_blank">LeetCode题解</a>|
10551056
|3541.找到频率最高的元音和辅音|简单|<a href="https://leetcode.cn/problems/find-most-frequent-vowel-and-consonant/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/09/13/LeetCode%203541.%E6%89%BE%E5%88%B0%E9%A2%91%E7%8E%87%E6%9C%80%E9%AB%98%E7%9A%84%E5%85%83%E9%9F%B3%E5%92%8C%E8%BE%85%E9%9F%B3/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/151653999" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-most-frequent-vowel-and-consonant/solutions/3780744/letmefly-3541zhao-dao-pin-lu-zui-gao-de-yv5vs/" target="_blank">LeetCode题解</a>|
10561057
|3577.统计计算机解锁顺序排列数|中等|<a href="https://leetcode.cn/problems/count-the-number-of-computer-unlocking-permutations/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/12/10/LeetCode%203577.%E7%BB%9F%E8%AE%A1%E8%AE%A1%E7%AE%97%E6%9C%BA%E8%A7%A3%E9%94%81%E9%A1%BA%E5%BA%8F%E6%8E%92%E5%88%97%E6%95%B0/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/155791805" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-the-number-of-computer-unlocking-permutations/solutions/3854206/letmefly-3577tong-ji-ji-suan-ji-jie-suo-5b6b8/" target="_blank">LeetCode题解</a>|
10571058
|3583.统计特殊三元组|中等|<a href="https://leetcode.cn/problems/count-special-triplets/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/12/09/LeetCode%203583.%E7%BB%9F%E8%AE%A1%E7%89%B9%E6%AE%8A%E4%B8%89%E5%85%83%E7%BB%84/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/155754955" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-special-triplets/solutions/3853381/letmefly-3583tong-ji-te-shu-san-yuan-zu-cdnx3/" target="_blank">LeetCode题解</a>|

0 commit comments

Comments
 (0)