chore: fix formatting

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2022-09-09 18:56:13 +02:00
parent d7f8f4fd7b
commit e3888415f7
Signed by: mfocko
GPG key ID: 7C47D46246790496
5 changed files with 17 additions and 20 deletions

View file

@ -1,20 +1,20 @@
use std::convert::TryInto;
impl Solution {
impl Solution {
pub fn pivot_index(nums: Vec<i32>) -> i32 {
let mut from_left: i32 = 0;
let mut from_right: i32 = nums.iter().sum();
for (i, e) in nums.iter().enumerate() {
from_right -= e;
if from_left == from_right {
return i.try_into().unwrap();
}
from_left += e;
}
-1
}
}

View file

@ -3,7 +3,7 @@ fun <A, B> product(xs: Sequence<A>, ys: Sequence<B>): Sequence<Pair<A, B>> =
fun <A, B> product(xs: Iterable<A>, ys: Iterable<B>): Sequence<Pair<A, B>> =
product(xs.asSequence(), ys.asSequence())
class Solution {
fun BFS(grid: Array<IntArray>, coords: Pair<Int, Int>): Int {
val queue = ArrayDeque<Pair<Int, Int>>()
@ -15,7 +15,7 @@ class Solution {
if (grid[y][x] != 1) {
continue
}
for ((dy, dx) in sequenceOf(0 to 1, 1 to 0, 0 to -1, -1 to 0)) {
if (!(y + dy in grid.indices) || !(x + dx in grid[y + dy].indices)) {
continue
@ -25,15 +25,15 @@ class Solution {
queue.addLast(y + dy to x + dx)
}
// mark it as done
grid[y][x] = 0
size++
}
return size
}
fun maxAreaOfIsland(grid: Array<IntArray>): Int =
product(grid.indices, grid.first().indices).map { BFS(grid, it) }.max() ?: 0
}

View file

@ -2,7 +2,7 @@ impl Solution {
pub fn max_coins(piles: Vec<i32>) -> i32 {
let mut sorted_piles = piles.clone();
sorted_piles.sort();
sorted_piles
.iter()
.rev()

View file

@ -9,7 +9,7 @@ class Solution {
.fold(0 to 0) { acc, boxType ->
if (acc.first < truckSize) {
val count = minOf(truckSize - acc.first, boxType.boxes)
(acc.first + count) to (acc.second + count * boxType.units)
} else {
acc

View file

@ -14,14 +14,11 @@ impl Reachable {
let reaches_pacific = y == 0 || x == 0;
let reaches_atlantic = y == max_y - 1 || x == max_x - 1;
if reaches_atlantic && reaches_pacific {
Reachable::Both
} else if reaches_atlantic {
Reachable::Atlantic
} else if reaches_pacific {
Reachable::Pacific
} else {
Reachable::None
match (reaches_pacific, reaches_atlantic) {
(true, true) => Reachable::Both,
(true, _) => Reachable::Pacific,
(_, true) => Reachable::Atlantic,
(_, _) => Reachable::None,
}
}
}