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 @@ -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
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
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;
}
}
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
}
}
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
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
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;
}
}
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
}
}