Skip to content

Commit a015979

Browse files
committed
feat: add solutions to lc problem: No.0908
No.0908.Smallest Range I
1 parent 6204107 commit a015979

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

solution/0900-0999/0908.Smallest Range I/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,28 @@ func min(a, b int) int {
125125
}
126126
```
127127

128+
### **TypeScript**
129+
130+
```ts
131+
function smallestRangeI(nums: number[], k: number): number {
132+
const max = nums.reduce((r, v) => Math.max(r, v));
133+
const min = nums.reduce((r, v) => Math.min(r, v));
134+
return Math.max(max - min - k * 2, 0);
135+
}
136+
```
137+
138+
### **Rust**
139+
140+
```rust
141+
impl Solution {
142+
pub fn smallest_range_i(nums: Vec<i32>, k: i32) -> i32 {
143+
let max = nums.iter().max().unwrap();
144+
let min = nums.iter().min().unwrap();
145+
0.max(max - min - k * 2)
146+
}
147+
}
148+
```
149+
128150
### **...**
129151

130152
```

solution/0900-0999/0908.Smallest Range I/README_EN.md

+22
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,28 @@ func min(a, b int) int {
115115
}
116116
```
117117

118+
### **TypeScript**
119+
120+
```ts
121+
function smallestRangeI(nums: number[], k: number): number {
122+
const max = nums.reduce((r, v) => Math.max(r, v));
123+
const min = nums.reduce((r, v) => Math.min(r, v));
124+
return Math.max(max - min - k * 2, 0);
125+
}
126+
```
127+
128+
### **Rust**
129+
130+
```rust
131+
impl Solution {
132+
pub fn smallest_range_i(nums: Vec<i32>, k: i32) -> i32 {
133+
let max = nums.iter().max().unwrap();
134+
let min = nums.iter().min().unwrap();
135+
0.max(max - min - k * 2)
136+
}
137+
}
138+
```
139+
118140
### **...**
119141

120142
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
impl Solution {
2+
pub fn smallest_range_i(nums: Vec<i32>, k: i32) -> i32 {
3+
let max = nums.iter().max().unwrap();
4+
let min = nums.iter().min().unwrap();
5+
0.max(max - min - k * 2)
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function smallestRangeI(nums: number[], k: number): number {
2+
const max = nums.reduce((r, v) => Math.max(r, v));
3+
const min = nums.reduce((r, v) => Math.min(r, v));
4+
return Math.max(max - min - k * 2, 0);
5+
}

0 commit comments

Comments
 (0)