Skip to content

Commit 31386dc

Browse files
authored
feat: add solutions to lc problem: No.2740 (doocs#3274)
No.2740.Find the Value of the Partition
1 parent 1dd28cb commit 31386dc

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

solution/2700-2799/2740.Find the Value of the Partition/README.md

+28
Original file line numberDiff line numberDiff 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 -->

solution/2700-2799/2740.Find the Value of the Partition/README_EN.md

+28
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
}

0 commit comments

Comments
 (0)