File tree Expand file tree Collapse file tree 4 files changed +74
-0
lines changed
solution/2700-2799/2740.Find the Value of the Partition Expand file tree Collapse file tree 4 files changed +74
-0
lines changed Original file line number Diff line number Diff line change @@ -135,6 +135,34 @@ func findValueOfPartition(nums []int) int {
135135}
136136```
137137
138+ #### TypeScript
139+
140+ ``` ts
141+ function findValueOfPartition(nums : number []): number {
142+ nums .sort ((a , b ) => a - b );
143+ let ans = Infinity ;
144+ for (let i = 1 ; i < nums .length ; ++ i ) {
145+ ans = Math .min (ans , Math .abs (nums [i ] - nums [i - 1 ]));
146+ }
147+ return ans ;
148+ }
149+ ```
150+
151+ #### Rust
152+
153+ ``` rust
154+ impl Solution {
155+ pub fn find_value_of_partition (mut nums : Vec <i32 >) -> i32 {
156+ nums . sort ();
157+ let mut ans = i32 :: MAX ;
158+ for i in 1 .. nums . len () {
159+ ans = ans . min (nums [i ] - nums [i - 1 ]);
160+ }
161+ ans
162+ }
163+ }
164+ ```
165+
138166<!-- tabs: end -->
139167
140168<!-- solution: end -->
Original file line number Diff line number Diff line change @@ -135,6 +135,34 @@ func findValueOfPartition(nums []int) int {
135135}
136136```
137137
138+ #### TypeScript
139+
140+ ``` ts
141+ function findValueOfPartition(nums : number []): number {
142+ nums .sort ((a , b ) => a - b );
143+ let ans = Infinity ;
144+ for (let i = 1 ; i < nums .length ; ++ i ) {
145+ ans = Math .min (ans , Math .abs (nums [i ] - nums [i - 1 ]));
146+ }
147+ return ans ;
148+ }
149+ ```
150+
151+ #### Rust
152+
153+ ``` rust
154+ impl Solution {
155+ pub fn find_value_of_partition (mut nums : Vec <i32 >) -> i32 {
156+ nums . sort ();
157+ let mut ans = i32 :: MAX ;
158+ for i in 1 .. nums . len () {
159+ ans = ans . min (nums [i ] - nums [i - 1 ]);
160+ }
161+ ans
162+ }
163+ }
164+ ```
165+
138166<!-- tabs: end -->
139167
140168<!-- solution: end -->
Original file line number Diff line number Diff line change 1+ impl Solution {
2+ pub fn find_value_of_partition ( mut nums : Vec < i32 > ) -> i32 {
3+ nums. sort ( ) ;
4+ let mut ans = i32:: MAX ;
5+ for i in 1 ..nums. len ( ) {
6+ ans = ans. min ( nums[ i] - nums[ i - 1 ] ) ;
7+ }
8+ ans
9+ }
10+ }
Original file line number Diff line number Diff line change 1+ function findValueOfPartition ( nums : number [ ] ) : number {
2+ nums . sort ( ( a , b ) => a - b ) ;
3+ let ans = Infinity ;
4+ for ( let i = 1 ; i < nums . length ; ++ i ) {
5+ ans = Math . min ( ans , Math . abs ( nums [ i ] - nums [ i - 1 ] ) ) ;
6+ }
7+ return ans ;
8+ }
You can’t perform that action at this time.
0 commit comments