Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add solutions to lc problems: No.3370,3371 #4804

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
yanglbme merged 1 commit into main from dev
Oct 28, 2025
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
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,34 @@ function smallestNumber(n: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn smallest_number(n: i32) -> i32 {
let mut x = 1;
while x - 1 < n {
x <<= 1;
}
x - 1
}
}
```

#### C#

```cs
public class Solution {
public int SmallestNumber(int n) {
int x = 1;
while (x - 1 < n) {
x <<= 1;
}
return x - 1;
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,34 @@ function smallestNumber(n: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn smallest_number(n: i32) -> i32 {
let mut x = 1;
while x - 1 < n {
x <<= 1;
}
x - 1
}
}
```

#### C#

```cs
public class Solution {
public int SmallestNumber(int n) {
int x = 1;
while (x - 1 < n) {
x <<= 1;
}
return x - 1;
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class Solution {
public int SmallestNumber(int n) {
int x = 1;
while (x - 1 < n) {
x <<= 1;
}
return x - 1;
}
}
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
impl Solution {
pub fn smallest_number(n: i32) -> i32 {
let mut x = 1;
while x - 1 < n {
x <<= 1;
}
x - 1
}
}
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,68 @@ function getLargestOutlier(nums: number[]): number {
}
```

#### Rust

```rust
use std::collections::HashMap;

impl Solution {
pub fn get_largest_outlier(nums: Vec<i32>) -> i32 {
let mut s = 0;
let mut cnt = HashMap::new();
for &x in &nums {
s += x;
*cnt.entry(x).or_insert(0) += 1;
}

let mut ans = i32::MIN;
for (&x, &v) in &cnt {
let t = s - x;
if t % 2 != 0 {
continue;
}
let y = t / 2;
if let Some(&count_y) = cnt.get(&y) {
if x != y || v > 1 {
ans = ans.max(x);
}
}
}
ans
}
}
```

#### C#

```cs
public class Solution {
public int GetLargestOutlier(int[] nums) {
int s = 0;
var cnt = new Dictionary<int, int>();
foreach (int x in nums) {
s += x;
if (!cnt.ContainsKey(x)) cnt[x] = 0;
cnt[x]++;
}

int ans = int.MinValue;
foreach (var kv in cnt) {
int x = kv.Key, v = kv.Value;
int t = s - x;
if (t % 2 != 0) continue;
int y = t / 2;
if (cnt.ContainsKey(y)) {
if (x != y || v > 1) {
ans = Math.Max(ans, x);
}
}
}
return ans;
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,68 @@ function getLargestOutlier(nums: number[]): number {
}
```

#### Rust

```rust
use std::collections::HashMap;

impl Solution {
pub fn get_largest_outlier(nums: Vec<i32>) -> i32 {
let mut s = 0;
let mut cnt = HashMap::new();
for &x in &nums {
s += x;
*cnt.entry(x).or_insert(0) += 1;
}

let mut ans = i32::MIN;
for (&x, &v) in &cnt {
let t = s - x;
if t % 2 != 0 {
continue;
}
let y = t / 2;
if let Some(&count_y) = cnt.get(&y) {
if x != y || v > 1 {
ans = ans.max(x);
}
}
}
ans
}
}
```

#### C#

```cs
public class Solution {
public int GetLargestOutlier(int[] nums) {
int s = 0;
var cnt = new Dictionary<int, int>();
foreach (int x in nums) {
s += x;
if (!cnt.ContainsKey(x)) cnt[x] = 0;
cnt[x]++;
}

int ans = int.MinValue;
foreach (var kv in cnt) {
int x = kv.Key, v = kv.Value;
int t = s - x;
if (t % 2 != 0) continue;
int y = t / 2;
if (cnt.ContainsKey(y)) {
if (x != y || v > 1) {
ans = Math.Max(ans, x);
}
}
}
return ans;
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
public class Solution {
public int GetLargestOutlier(int[] nums) {
int s = 0;
var cnt = new Dictionary<int, int>();
foreach (int x in nums) {
s += x;
if (!cnt.ContainsKey(x)) cnt[x] = 0;
cnt[x]++;
}

int ans = int.MinValue;
foreach (var kv in cnt) {
int x = kv.Key, v = kv.Value;
int t = s - x;
if (t % 2 != 0) continue;
int y = t / 2;
if (cnt.ContainsKey(y)) {
if (x != y || v > 1) {
ans = Math.Max(ans, x);
}
}
}
return ans;
}
}
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use std::collections::HashMap;

impl Solution {
pub fn get_largest_outlier(nums: Vec<i32>) -> i32 {
let mut s = 0;
let mut cnt = HashMap::new();
for &x in &nums {
s += x;
*cnt.entry(x).or_insert(0) += 1;
}

let mut ans = i32::MIN;
for (&x, &v) in &cnt {
let t = s - x;
if t % 2 != 0 {
continue;
}
let y = t / 2;
if let Some(&count_y) = cnt.get(&y) {
if x != y || v > 1 {
ans = ans.max(x);
}
}
}
ans
}
}

AltStyle によって変換されたページ (->オリジナル) /