style(kt): reformat ‹695. Max Area of Island›

• reformat
• rename function to follow camel-case convention

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-05-17 18:24:05 +02:00
parent aaaebf1d52
commit 5bdc00e5ca
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -1,11 +1,18 @@
fun <A, B> product(xs: Sequence<A>, ys: Sequence<B>): Sequence<Pair<A, B>> = fun <A, B> product(
xs.flatMap { x -> ys.map { y -> x to y } } xs: Sequence<A>,
ys: Sequence<B>,
): Sequence<Pair<A, B>> = xs.flatMap { x -> ys.map { y -> x to y } }
fun <A, B> product(xs: Iterable<A>, ys: Iterable<B>): Sequence<Pair<A, B>> = fun <A, B> product(
product(xs.asSequence(), ys.asSequence()) xs: Iterable<A>,
ys: Iterable<B>,
): Sequence<Pair<A, B>> = product(xs.asSequence(), ys.asSequence())
class Solution { class Solution {
fun BFS(grid: Array<IntArray>, coords: Pair<Int, Int>): Int { fun runBFS(
grid: Array<IntArray>,
coords: Pair<Int, Int>,
): Int {
val queue = ArrayDeque<Pair<Int, Int>>() val queue = ArrayDeque<Pair<Int, Int>>()
queue.addLast(coords) queue.addLast(coords)
@ -34,6 +41,5 @@ class Solution {
return size return size
} }
fun maxAreaOfIsland(grid: Array<IntArray>): Int = fun maxAreaOfIsland(grid: Array<IntArray>): Int = product(grid.indices, grid.first().indices).map { runBFS(grid, it) }.max() ?: 0
product(grid.indices, grid.first().indices).map { BFS(grid, it) }.max() ?: 0
} }