File tree 4 files changed +56
-0
lines changed
solution/0900-0999/0908.Smallest Range I
4 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,28 @@ func min(a, b int) int {
125
125
}
126
126
```
127
127
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
+
128
150
### ** ...**
129
151
130
152
```
Original file line number Diff line number Diff line change @@ -115,6 +115,28 @@ func min(a, b int) int {
115
115
}
116
116
```
117
117
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
+
118
140
### ** ...**
119
141
120
142
```
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments