From d92a22e63226bf699cbf9100a59ef9a38a96e15f Mon Sep 17 00:00:00 2001 From: isaiahliu Date: Thu, 26 Dec 2024 00:06:01 +0800 Subject: [PATCH] 1 --- src/main/kotlin/p25xx/Problem2500.kt | 6 ++--- src/main/kotlin/p30xx/Problem3083.kt | 37 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/p30xx/Problem3083.kt diff --git a/src/main/kotlin/p25xx/Problem2500.kt b/src/main/kotlin/p25xx/Problem2500.kt index 810bf744..e8ca9b23 100644 --- a/src/main/kotlin/p25xx/Problem2500.kt +++ b/src/main/kotlin/p25xx/Problem2500.kt @@ -7,9 +7,9 @@ fun main() { fun deleteGreatestValue(grid: Array): Int { grid.forEach { it.sort() } - return grid[0].indices.map { i -> - grid.map { it[i] }.max() - }.sum() + return grid[0].indices.sumOf { i -> + grid.maxOf { it[i] } + } } } diff --git a/src/main/kotlin/p30xx/Problem3083.kt b/src/main/kotlin/p30xx/Problem3083.kt new file mode 100644 index 00000000..29defbe9 --- /dev/null +++ b/src/main/kotlin/p30xx/Problem3083.kt @@ -0,0 +1,37 @@ +package p30xx + +import util.expect + +fun main() { + class Solution { + fun isSubstringPresent(s: String): Boolean { + val befores = Array(26) { hashSetOf() } + val afters = Array(26) { hashSetOf() } + + s.forEachIndexed { index, ch -> + s.getOrNull(index - 1)?.also { + if (it - 'a' in afters[ch - 'a']) { + return true + } + + befores[ch - 'a'] += it - 'a' + } + s.getOrNull(index + 1)?.also { + if (it - 'a' in befores[ch - 'a']) { + return true + } + + afters[ch - 'a'] += it - 'a' + } + } + + return false + } + } + + expect { + Solution().isSubstringPresent( + "" + ) + } +}