From 15ca3ea3d6103946f376e350784590272928e84c Mon Sep 17 00:00:00 2001 From: isaiahliu Date: Fri, 20 Dec 2024 00:41:10 +0800 Subject: [PATCH] 1 --- src/main/kotlin/p31xx/Problem3138.kt | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/kotlin/p31xx/Problem3138.kt diff --git a/src/main/kotlin/p31xx/Problem3138.kt b/src/main/kotlin/p31xx/Problem3138.kt new file mode 100644 index 00000000..739bf136 --- /dev/null +++ b/src/main/kotlin/p31xx/Problem3138.kt @@ -0,0 +1,35 @@ +package p31xx + +import util.expect + +fun main() { + class Solution { + fun minAnagramLength(s: String): Int { + for (i in 1..s.length) { + if (s.length % i == 0) { + val set = hashSetOf() + + for (index in s.indices step i) { + set.add(s.substring(index, index + i).toCharArray().also { it.sort() }.concatToString()) + + if (set.size > 1) { + break + } + } + + if (set.size == 1) { + return i + } + } + } + + return s.length + } + } + + expect { + Solution().minAnagramLength( + "" + ) + } +}