Skip to content

feat: add solutions to lc problem: No.2740 #3274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: add solutions to lc problem: No.2740
No.2740.Find the Value of the Partition
  • Loading branch information
yanglbme committed Jul 15, 2024
commit 2c140042b9aa3bccb5131e250ab64013a1d5caf1
28 changes: 28 additions & 0 deletions solution/2700-2799/2740.Find the Value of the Partition/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,34 @@ func findValueOfPartition(nums []int) int {
}
```

#### TypeScript

```ts
function findValueOfPartition(nums: number[]): number {
nums.sort((a, b) => a - b);
let ans = Infinity;
for (let i = 1; i < nums.length; ++i) {
ans = Math.min(ans, Math.abs(nums[i] - nums[i - 1]));
}
return ans;
}
```

#### Rust

```rust
impl Solution {
pub fn find_value_of_partition(mut nums: Vec<i32>) -> i32 {
nums.sort();
let mut ans = i32::MAX;
for i in 1..nums.len() {
ans = ans.min(nums[i] - nums[i - 1]);
}
ans
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,34 @@ func findValueOfPartition(nums []int) int {
}
```

#### TypeScript

```ts
function findValueOfPartition(nums: number[]): number {
nums.sort((a, b) => a - b);
let ans = Infinity;
for (let i = 1; i < nums.length; ++i) {
ans = Math.min(ans, Math.abs(nums[i] - nums[i - 1]));
}
return ans;
}
```

#### Rust

```rust
impl Solution {
pub fn find_value_of_partition(mut nums: Vec<i32>) -> i32 {
nums.sort();
let mut ans = i32::MAX;
for i in 1..nums.len() {
ans = ans.min(nums[i] - nums[i - 1]);
}
ans
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
impl Solution {
pub fn find_value_of_partition(mut nums: Vec<i32>) -> i32 {
nums.sort();
let mut ans = i32::MAX;
for i in 1..nums.len() {
ans = ans.min(nums[i] - nums[i - 1]);
}
ans
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function findValueOfPartition(nums: number[]): number {
nums.sort((a, b) => a - b);
let ans = Infinity;
for (let i = 1; i < nums.length; ++i) {
ans = Math.min(ans, Math.abs(nums[i] - nums[i - 1]));
}
return ans;
}
Loading