Skip to content

Commit 71eb228

Browse files
committed
✨feat: add 1619
1 parent 8474ca1 commit 71eb228

File tree

3 files changed

+99
-7
lines changed

3 files changed

+99
-7
lines changed

Index/模拟.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
| [1606. 找到处理最多请求的服务器](https://leetcode-cn.com/problems/find-servers-that-handled-most-number-of-requests/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/find-servers-that-handled-most-number-of-requests/solution/by-ac_oier-zgm6/) | 困难 | 🤩🤩🤩🤩 |
170170
| [1608. 特殊数组的特征值](https://leetcode.cn/problems/special-array-with-x-elements-greater-than-or-equal-x/) | [LeetCode 题解链接](https://leetcode.cn/problems/special-array-with-x-elements-greater-than-or-equal-x/solution/by-ac_oier-z525/) | 简单 | 🤩🤩🤩🤩🤩 |
171171
| [1614. 括号的最大嵌套深度](https://leetcode-cn.com/problems/maximum-nesting-depth-of-the-parentheses/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/maximum-nesting-depth-of-the-parentheses/solution/gong-shui-san-xie-jian-dan-mo-ni-ti-by-a-pf5d/) | 简单 | 🤩🤩🤩🤩🤩 |
172+
| [1619. 删除某些元素后的数组均值](https://leetcode.cn/problems/mean-of-array-after-removing-some-elements/) | [LeetCode 题解链接](https://leetcode.cn/problems/mean-of-array-after-removing-some-elements/solution/by-ac_oier-73w7/) | 简单 | 🤩🤩🤩🤩 |
172173
| [1629. 按键持续时间最长的键](https://leetcode-cn.com/problems/slowest-key/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/slowest-key/solution/gong-shui-san-xie-jian-dan-mo-ni-ti-by-a-zjwb/) | 简单 | 🤩🤩🤩🤩🤩 |
173174
| [1646. 获取生成数组中的最大值](https://leetcode-cn.com/problems/get-maximum-in-generated-array/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/get-maximum-in-generated-array/solution/gong-shui-san-xie-jian-dan-mo-ni-ti-by-a-sj53/) | 简单 | 🤩🤩🤩🤩 |
174175
| [1656. 设计有序流](https://leetcode.cn/problems/design-an-ordered-stream/) | [LeetCode 题解链接](https://leetcode.cn/problems/design-an-ordered-stream/solution/by-ac_oier-5pe8/) | 简单 | 🤩🤩🤩🤩 |
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
### 题目描述
2+
3+
这是 LeetCode 上的 **[1619. 删除某些元素后的数组均值](https://leetcode.cn/problems/mean-of-array-after-removing-some-elements/solution/by-ac_oier-73w7/)** ,难度为 **简单**
4+
5+
Tag : 「模拟」、「排序」
6+
7+
8+
9+
给你一个整数数组 `arr`,请你删除最小 `5%` 的数字和最大 `5%` 的数字后,剩余数字的平均值。
10+
11+
与 标准答案 误差在 $10^{-5}$ 的结果都被视为正确结果。
12+
13+
示例 1:
14+
```
15+
输入:arr = [1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3]
16+
17+
输出:2.00000
18+
19+
解释:删除数组中最大和最小的元素后,所有元素都等于 2,所以平均值为 2 。
20+
```
21+
示例 2:
22+
```
23+
输入:arr = [6,2,7,5,1,2,0,3,10,2,5,0,5,5,0,8,7,6,8,0]
24+
25+
输出:4.00000
26+
```
27+
示例 3:
28+
```
29+
输入:arr = [6,0,7,0,7,5,7,8,3,4,0,7,8,1,6,8,1,1,2,4,8,1,9,5,4,3,8,5,10,8,6,6,1,0,6,10,8,2,3,4]
30+
31+
输出:4.77778
32+
```
33+
示例 4:
34+
```
35+
输入:arr = [9,7,8,7,7,8,4,4,6,8,8,7,6,8,8,9,2,6,0,0,1,10,8,6,3,3,5,1,10,9,0,7,10,0,10,4,1,10,6,9,3,6,0,0,2,7,0,6,7,2,9,7,7,3,0,1,6,1,10,3]
36+
37+
输出:5.27778
38+
```
39+
示例 5:
40+
```
41+
输入:arr = [4,8,4,10,0,7,1,3,7,8,8,3,4,1,6,2,1,1,8,0,9,8,0,3,9,10,3,10,1,10,7,3,2,1,4,9,10,7,6,4,0,8,5,1,2,1,6,2,5,0,7,10,9,10,3,7,10,5,8,5,7,6,7,6,10,9,5,10,5,5,7,2,10,7,7,8,2,0,1,1]
42+
43+
输出:5.29167
44+
```
45+
46+
提示:
47+
* $20 <= arr.length <= 1000$
48+
* `arr.length` 是 `20` 的 倍数 
49+
* $0 <= arr[i] <= 10^5$
50+
51+
---
52+
53+
### 模拟
54+
55+
根据题意进行模拟即可:先对 `arr` 进行排序,再计算出待统计的左右端点(端点以外的数值为 `5%` 最值),最后计算出相应均值。
56+
57+
Java 代码:
58+
```Java
59+
class Solution {
60+
public double trimMean(int[] arr) {
61+
Arrays.sort(arr);
62+
int n = arr.length, tot = 0;
63+
for (int i = n / 20; i < n - n / 20; i++) tot += arr[i];
64+
return tot * 1.0 / (n * 0.9);
65+
}
66+
}
67+
```
68+
TypeScript 代码:
69+
```TypeScript
70+
function trimMean(arr: number[]): number {
71+
arr.sort((a,b)=>a-b)
72+
let n = arr.length, tot = 0
73+
for (let i = n / 20; i < n - n / 20; i++) tot += arr[i]
74+
return tot / (n * 0.9)
75+
};
76+
```
77+
* 时间复杂度:$O(n\log{n})$
78+
* 空间复杂度:$O(\log{n})$
79+
80+
---
81+
82+
### 最后
83+
84+
这是我们「刷穿 LeetCode」系列文章的第 `No.1619` 篇,系列开始于 2021/01/01,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完。
85+
86+
在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。
87+
88+
为了方便各位同学能够电脑上进行调试和提交代码,我建立了相关的仓库:https://github.com/SharingSource/LogicStack-LeetCode
89+
90+
在仓库地址里,你可以看到系列文章的题解链接、系列文章的相应代码、LeetCode 原题链接和其他优选题解。
91+

LeetCode/781-790/786. 第 K 个最小的素数分数(困难).md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### 题目描述
22

3-
这是 LeetCode 上的 **[786. 第 K 个最小的素数分数](https://leetcode-cn.com/problems/k-th-smallest-prime-fraction/solution/gong-shui-san-xie-yi-ti-shuang-jie-you-x-8ymk/)** ,难度为 **困难**
3+
这是 LeetCode 上的 **[786. 第 K 个最小的素数分数](https://leetcode-cn.com/problems/k-th-smallest-prime-fraction/solution/gong-shui-san-xie-yi-ti-shuang-jie-you-x-8ymk/)** ,难度为 **中等**
44

55
Tag : 「优先队列(堆)」、「多路归并」、「二分」、「双指针」
66

@@ -34,11 +34,11 @@ Tag : 「优先队列(堆)」、「多路归并」、「二分」、「双
3434

3535
提示:
3636
* $2 <= arr.length <= 1000$
37-
* $1 <= arr[i] <= 3 * 10^4$
38-
* $arr[0] == 1$
37+
* $1 <= arr[i] <= 3 \times 10^4$
38+
* $arr[0] = 1$
3939
* $arr[i]$ 是一个 素数 ,$i > 0$
4040
* $arr$ 中的所有数字 互不相同 ,且按**严格递增**排序
41-
* $1 <= k <= arr.length * (arr.length - 1) / 2$
41+
* $1 <= k <= arr.length \times (arr.length - 1) / 2$
4242

4343
---
4444

@@ -74,7 +74,7 @@ class Solution {
7474
}
7575
}
7676
```
77-
* 时间复杂度:扫描所有的点对复杂度为 $O(n^2)$;将二元组入堆和出堆的复杂度为 $O(\log{k})$。整体复杂度为 $O(n^2 * \log{k})$
77+
* 时间复杂度:扫描所有的点对复杂度为 $O(n^2)$;将二元组入堆和出堆的复杂度为 $O(\log{k})$。整体复杂度为 $O(n^2\log{k})$
7878
* 空间复杂度:$O(k)$
7979

8080
---
@@ -115,7 +115,7 @@ class Solution {
115115
}
116116
}
117117
```
118-
* 时间复杂度:起始将 $n - 1$ 个序列的头部元素放入堆中,复杂度为 $O(n\log{n})$;然后重复 $k$ 次操作得到第 $k$ 小的值,复杂度为 $O(k\log{n})$。整体复杂度为 $O(\max(n, k) * \log{n})$
118+
* 时间复杂度:起始将 $n - 1$ 个序列的头部元素放入堆中,复杂度为 $O(n\log{n})$;然后重复 $k$ 次操作得到第 $k$ 小的值,复杂度为 $O(k\log{n})$。整体复杂度为 $O(\max(n, k) \times \log{n})$
119119
* 空间复杂度:$O(n)$
120120

121121
---
@@ -163,7 +163,7 @@ class Solution {
163163
}
164164
}
165165
```
166-
* 时间复杂度:二分次数取决于精度,精度为 $C = 10^8$,二分复杂度为 $O(\log{C});$`check` 的复杂度为 $O(n)$。整体复杂度为 $O(n * \log{C})$
166+
* 时间复杂度:二分次数取决于精度,精度为 $C = 10^8$,二分复杂度为 $O(\log{C});$`check` 的复杂度为 $O(n)$。整体复杂度为 $O(n\log{C})$
167167
* 空间复杂度:$O(1)$
168168

169169
---

0 commit comments

Comments
 (0)