Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,48 @@ function partitionArray(nums: number[], k: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn partition_array(mut nums: Vec<i32>, k: i32) -> i32 {
nums.sort();
let mut ans = 1;
let mut a = nums[0];

for &b in nums.iter() {
if b - a > k {
a = b;
ans += 1;
}
}

ans
}
}
```

#### Rust

```rust
public class Solution {
public int PartitionArray(int[] nums, int k) {
Array.Sort(nums);
int ans = 1;
int a = nums[0];

foreach (int b in nums) {
if (b - a > k) {
a = b;
ans++;
}
}

return ans;
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,48 @@ function partitionArray(nums: number[], k: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn partition_array(mut nums: Vec<i32>, k: i32) -> i32 {
nums.sort();
let mut ans = 1;
let mut a = nums[0];

for &b in nums.iter() {
if b - a > k {
a = b;
ans += 1;
}
}

ans
}
}
```

#### Rust

```rust
public class Solution {
public int PartitionArray(int[] nums, int k) {
Array.Sort(nums);
int ans = 1;
int a = nums[0];

foreach (int b in nums) {
if (b - a > k) {
a = b;
ans++;
}
}

return ans;
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class Solution {
public int PartitionArray(int[] nums, int k) {
Array.Sort(nums);
int ans = 1;
int a = nums[0];

foreach (int b in nums) {
if (b - a > k) {
a = b;
ans++;
}
}

return ans;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
impl Solution {
pub fn partition_array(mut nums: Vec<i32>, k: i32) -> i32 {
nums.sort();
let mut ans = 1;
let mut a = nums[0];

for &b in nums.iter() {
if b - a > k {
a = b;
ans += 1;
}
}

ans
}
}