Skip to content

Commit 45be9e2

Browse files
committed
feat: add rust solution to lc problem: No.1619
No.1619.Mean of Array After Removing Some Elements
1 parent 788fbf2 commit 45be9e2

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

solution/1600-1699/1619.Mean of Array After Removing Some Elements/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,23 @@ func trimMean(arr []int) float64 {
149149
}
150150
```
151151

152+
### **Rust**
153+
154+
```rust
155+
impl Solution {
156+
pub fn trim_mean(mut arr: Vec<i32>) -> f64 {
157+
arr.sort();
158+
let n = arr.len();
159+
let count = (n as f64 * 0.05).floor() as usize;
160+
let mut sum = 0;
161+
for i in count..n - count {
162+
sum += arr[i];
163+
}
164+
sum as f64 / (n as f64 * 0.9)
165+
}
166+
}
167+
```
168+
152169
### **...**
153170

154171
```

solution/1600-1699/1619.Mean of Array After Removing Some Elements/README_EN.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,23 @@ func trimMean(arr []int) float64 {
117117
}
118118
```
119119

120+
### **Rust**
121+
122+
```rust
123+
impl Solution {
124+
pub fn trim_mean(mut arr: Vec<i32>) -> f64 {
125+
arr.sort();
126+
let n = arr.len();
127+
let count = (n as f64 * 0.05).floor() as usize;
128+
let mut sum = 0;
129+
for i in count..n - count {
130+
sum += arr[i];
131+
}
132+
sum as f64 / (n as f64 * 0.9)
133+
}
134+
}
135+
```
136+
120137
### **...**
121138

122139
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
impl Solution {
2+
pub fn trim_mean(mut arr: Vec<i32>) -> f64 {
3+
arr.sort();
4+
let n = arr.len();
5+
let count = (n as f64 * 0.05).floor() as usize;
6+
let mut sum = 0;
7+
for i in count..n - count {
8+
sum += arr[i];
9+
}
10+
sum as f64 / (n as f64 * 0.9)
11+
}
12+
}

0 commit comments

Comments
 (0)