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 @@ -151,6 +151,35 @@ function flowerGame(n: number, m: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn flower_game(n: i32, m: i32) -> i64 {
let a1 = ((n + 1) / 2) as i64;
let b1 = ((m + 1) / 2) as i64;
let a2 = (n / 2) as i64;
let b2 = (m / 2) as i64;
a1 * b2 + a2 * b1
}
}
```

#### JavaScript

```js
/**
* @param {number} n
* @param {number} m
* @return {number}
*/
var flowerGame = function (n, m) {
const [a1, b1] = [(n + 1) >> 1, (m + 1) >> 1];
const [a2, b2] = [n >> 1, m >> 1];
return a1 * b2 + a2 * b1;
};
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down Expand Up @@ -220,6 +249,29 @@ function flowerGame(n: number, m: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn flower_game(n: i32, m: i32) -> i64 {
(n as i64 * m as i64) / 2
}
}
```

#### JavaScript

```js
/**
* @param {number} n
* @param {number} m
* @return {number}
*/
var flowerGame = function (n, m) {
return Number(((BigInt(n) * BigInt(m)) / 2n) | 0n);
};
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,35 @@ function flowerGame(n: number, m: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn flower_game(n: i32, m: i32) -> i64 {
let a1 = ((n + 1) / 2) as i64;
let b1 = ((m + 1) / 2) as i64;
let a2 = (n / 2) as i64;
let b2 = (m / 2) as i64;
a1 * b2 + a2 * b1
}
}
```

#### JavaScript

```js
/**
* @param {number} n
* @param {number} m
* @return {number}
*/
var flowerGame = function (n, m) {
const [a1, b1] = [(n + 1) >> 1, (m + 1) >> 1];
const [a2, b2] = [n >> 1, m >> 1];
return a1 * b2 + a2 * b1;
};
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down Expand Up @@ -218,6 +247,29 @@ function flowerGame(n: number, m: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn flower_game(n: i32, m: i32) -> i64 {
(n as i64 * m as i64) / 2
}
}
```

#### JavaScript

```js
/**
* @param {number} n
* @param {number} m
* @return {number}
*/
var flowerGame = function (n, m) {
return Number(((BigInt(n) * BigInt(m)) / 2n) | 0n);
};
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @param {number} n
* @param {number} m
* @return {number}
*/
var flowerGame = function (n, m) {
const [a1, b1] = [(n + 1) >> 1, (m + 1) >> 1];
const [a2, b2] = [n >> 1, m >> 1];
return a1 * b2 + a2 * b1;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
impl Solution {
pub fn flower_game(n: i32, m: i32) -> i64 {
let a1 = ((n + 1) / 2) as i64;
let b1 = ((m + 1) / 2) as i64;
let a2 = (n / 2) as i64;
let b2 = (m / 2) as i64;
a1 * b2 + a2 * b1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @param {number} n
* @param {number} m
* @return {number}
*/
var flowerGame = function (n, m) {
return Number(((BigInt(n) * BigInt(m)) / 2n) | 0n);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
impl Solution {
pub fn flower_game(n: i32, m: i32) -> i64 {
(n as i64 * m as i64) / 2
}
}
46 changes: 46 additions & 0 deletions solution/3500-3599/3516.Find Closest Person/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,52 @@ function findClosest(x: number, y: number, z: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn find_closest(x: i32, y: i32, z: i32) -> i32 {
let a = (x - z).abs();
let b = (y - z).abs();
if a == b {
0
} else if a < b {
1
} else {
2
}
}
}
```

#### JavaScript

```js
/**
* @param {number} x
* @param {number} y
* @param {number} z
* @return {number}
*/
var findClosest = function (x, y, z) {
const a = Math.abs(x - z);
const b = Math.abs(y - z);
return a === b ? 0 : a < b ? 1 : 2;
};
```

#### C#

```cs
public class Solution {
public int FindClosest(int x, int y, int z) {
int a = Math.Abs(x - z);
int b = Math.Abs(y - z);
return a == b ? 0 : (a < b ? 1 : 2);
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
46 changes: 46 additions & 0 deletions solution/3500-3599/3516.Find Closest Person/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,52 @@ function findClosest(x: number, y: number, z: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn find_closest(x: i32, y: i32, z: i32) -> i32 {
let a = (x - z).abs();
let b = (y - z).abs();
if a == b {
0
} else if a < b {
1
} else {
2
}
}
}
```

#### JavaScript

```js
/**
* @param {number} x
* @param {number} y
* @param {number} z
* @return {number}
*/
var findClosest = function (x, y, z) {
const a = Math.abs(x - z);
const b = Math.abs(y - z);
return a === b ? 0 : a < b ? 1 : 2;
};
```

#### C#

```cs
public class Solution {
public int FindClosest(int x, int y, int z) {
int a = Math.Abs(x - z);
int b = Math.Abs(y - z);
return a == b ? 0 : (a < b ? 1 : 2);
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
7 changes: 7 additions & 0 deletions solution/3500-3599/3516.Find Closest Person/Solution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public class Solution {
public int FindClosest(int x, int y, int z) {
int a = Math.Abs(x - z);
int b = Math.Abs(y - z);
return a == b ? 0 : (a < b ? 1 : 2);
}
}
11 changes: 11 additions & 0 deletions solution/3500-3599/3516.Find Closest Person/Solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @param {number} x
* @param {number} y
* @param {number} z
* @return {number}
*/
var findClosest = function (x, y, z) {
const a = Math.abs(x - z);
const b = Math.abs(y - z);
return a === b ? 0 : a < b ? 1 : 2;
};
13 changes: 13 additions & 0 deletions solution/3500-3599/3516.Find Closest Person/Solution.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
impl Solution {
pub fn find_closest(x: i32, y: i32, z: i32) -> i32 {
let a = (x - z).abs();
let b = (y - z).abs();
if a == b {
0
} else if a < b {
1
} else {
2
}
}
}