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
13 changes: 13 additions & 0 deletions solution/2800-2899/2833.Furthest Point From Origin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ function furthestDistanceFromOrigin(moves: string): number {
}
```

#### Rust

```rust
impl Solution {
pub fn furthest_distance_from_origin(moves: String) -> i32 {
let l = moves.chars().filter(|&c| c == 'L').count() as i32;
let r = moves.chars().filter(|&c| c == 'R').count() as i32;
let blank = moves.chars().filter(|&c| c == '_').count() as i32;
(l - r).abs() + blank
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
13 changes: 13 additions & 0 deletions solution/2800-2899/2833.Furthest Point From Origin/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,19 @@ function furthestDistanceFromOrigin(moves: string): number {
}
```

#### Rust

```rust
impl Solution {
pub fn furthest_distance_from_origin(moves: String) -> i32 {
let l = moves.chars().filter(|&c| c == 'L').count() as i32;
let r = moves.chars().filter(|&c| c == 'R').count() as i32;
let blank = moves.chars().filter(|&c| c == '_').count() as i32;
(l - r).abs() + blank
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
impl Solution {
pub fn furthest_distance_from_origin(moves: String) -> i32 {
let l = moves.chars().filter(|&c| c == 'L').count() as i32;
let r = moves.chars().filter(|&c| c == 'R').count() as i32;
let blank = moves.chars().filter(|&c| c == '_').count() as i32;
(l - r).abs() + blank
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ tags:
<strong>输入:</strong>n = 3, target = 3
<strong>输出:</strong>8
<strong>解释:</strong>
nums = [1,3,4] 是美丽数组。
- nums 的长度为 n = 3 。
- nums 由两两互不相同的正整数组成。
nums = [1,3,4] 是美丽数组。
- nums 的长度为 n = 3 。
- nums 由两两互不相同的正整数组成。
- 不存在两个不同下标 i 和 j ,使得 nums[i] + nums[j] == 3 。
可以证明 8 是符合条件的美丽数组所可能具备的最小和。</pre>

Expand Down Expand Up @@ -170,6 +170,25 @@ function minimumPossibleSum(n: number, target: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn minimum_possible_sum(n: i32, target: i32) -> i32 {
const MOD: i64 = 1_000_000_007;
let n = n as i64;
let target = target as i64;
let m = target / 2;
if n <= m {
return ((1 + n) * n / 2 % MOD) as i32;
}
let a = (1 + m) * m / 2 % MOD;
let b = (target + target + n - m - 1) * (n - m) / 2 % MOD;
((a + b) % MOD) as i32
}
}
```

#### C#

```cs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,25 @@ function minimumPossibleSum(n: number, target: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn minimum_possible_sum(n: i32, target: i32) -> i32 {
const MOD: i64 = 1_000_000_007;
let n = n as i64;
let target = target as i64;
let m = target / 2;
if n <= m {
return ((1 + n) * n / 2 % MOD) as i32;
}
let a = (1 + m) * m / 2 % MOD;
let b = (target + target + n - m - 1) * (n - m) / 2 % MOD;
((a + b) % MOD) as i32
}
}
```

#### C#

```cs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
impl Solution {
pub fn minimum_possible_sum(n: i32, target: i32) -> i32 {
const MOD: i64 = 1_000_000_007;
let n = n as i64;
let target = target as i64;
let m = target / 2;
if n <= m {
return ((1 + n) * n / 2 % MOD) as i32;
}
let a = (1 + m) * m / 2 % MOD;
let b = (target + target + n - m - 1) * (n - m) / 2 % MOD;
((a + b) % MOD) as i32
}
}
Loading