1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-16 16:36:56 +02:00

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