Skip to content

Commit

Permalink
feat: add solutions to lc problem: No.0908
Browse files Browse the repository at this point in the history
No.0908.Smallest Range I
  • Loading branch information
YangFong committed Apr 30, 2022
1 parent 6204107 commit a015979
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
22 changes: 22 additions & 0 deletions solution/0900-0999/0908.Smallest Range I/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,28 @@ func min(a, b int) int {
}
```

### **TypeScript**

```ts
function smallestRangeI(nums: number[], k: number): number {
const max = nums.reduce((r, v) => Math.max(r, v));
const min = nums.reduce((r, v) => Math.min(r, v));
return Math.max(max - min - k * 2, 0);
}
```

### **Rust**

```rust
impl Solution {
pub fn smallest_range_i(nums: Vec<i32>, k: i32) -> i32 {
let max = nums.iter().max().unwrap();
let min = nums.iter().min().unwrap();
0.max(max - min - k * 2)
}
}
```

### **...**

```
Expand Down
22 changes: 22 additions & 0 deletions solution/0900-0999/0908.Smallest Range I/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,28 @@ func min(a, b int) int {
}
```

### **TypeScript**

```ts
function smallestRangeI(nums: number[], k: number): number {
const max = nums.reduce((r, v) => Math.max(r, v));
const min = nums.reduce((r, v) => Math.min(r, v));
return Math.max(max - min - k * 2, 0);
}
```

### **Rust**

```rust
impl Solution {
pub fn smallest_range_i(nums: Vec<i32>, k: i32) -> i32 {
let max = nums.iter().max().unwrap();
let min = nums.iter().min().unwrap();
0.max(max - min - k * 2)
}
}
```

### **...**

```
Expand Down
7 changes: 7 additions & 0 deletions solution/0900-0999/0908.Smallest Range I/Solution.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
impl Solution {
pub fn smallest_range_i(nums: Vec<i32>, k: i32) -> i32 {
let max = nums.iter().max().unwrap();
let min = nums.iter().min().unwrap();
0.max(max - min - k * 2)
}
}
5 changes: 5 additions & 0 deletions solution/0900-0999/0908.Smallest Range I/Solution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function smallestRangeI(nums: number[], k: number): number {
const max = nums.reduce((r, v) => Math.max(r, v));
const min = nums.reduce((r, v) => Math.min(r, v));
return Math.max(max - min - k * 2, 0);
}

0 comments on commit a015979

Please sign in to comment.