Logo
TGCATALOG
Catalog Collections Blog
Kotlin | LeetCode

Kotlin | LeetCode

LeetCode problems and solutions in Kotlin.

No ratings
431
02.12.2026
431
02.12.2026
No ratings
431
02.12.2026
Safe redirect via bot
О канале

LeetCode problems and solutions in Kotlin.

Подписчиков —
Тематика Technology
Ссылка @easy_kotlin_task

We also recommend

Kekaton AI | Voiceover and voice clone
Kekaton AI | Voiceover and voice clone
Bot

AI bot for text-to-speech and voice cloning in Telegram. Create audio using neural network quickly and easily.

Description

LeetCode problem solutions in Kotlin. Optimized code for mobile developers and algorithm specialists.

Latest posts

Kotlin | LeetCode
Kotlin | LeetCode
🔒Открыть пост
и посмотреть медиа
Задача: 56. Merge Intervals Сложность: medium Дан массив интервалов, где intervals[i] = [starti, endi]. Объедините все перекрывающиеся интервалы и верните массив неперекрывающихся интервалов, которые покрывают все интервалы во входных данных. Пример: Input: intervals = [[1,3],[2,6],[8,10],[15,18]] Output: [[1,6],[8,10],[15,18]] Explanation: Since intervals [1,3] and [2,6] overlap, merge them into [1,6]. 👨💻 Алгоритм: 1⃣Представление графа: Имея представленную интуицию, мы можем изобразить граф в виде списка смежности, вставляя направленные ребра в обоих направлениях, чтобы симулировать неориентированные ребра. 2⃣Определение компонент связности: Для определения, в какой компоненте связности находится каждый узел, мы выполняем обходы графа от произвольных непосещенных узлов до тех пор, пока все узлы не будут посещены. Для эффективности мы храним посещенные узлы в множестве (Set), что позволяет проводить проверки на принадлежность и вставку за константное время. 3⃣Объединение интервалов внутри компонент: Наконец, мы рассматриваем каждую связную компоненту, объединяя все её интервалы, создавая новый интервал с началом, равным минимальному началу среди всех интервалов в компоненте, и концом, равным максимальному концу. 😎 Решение: class Solution { private fun overlap(a: IntArray, b: IntArray): Boolean { return a[0] () for (i in intervals.indices) { for (j in i + 1 until intervals.size) { if (overlap(intervals[i], intervals[j])) { graph.getOrPut(intervals[i].toList()) { mutableListOf() }.add(intervals[j]) graph.getOrPut(intervals[j].toList()) { mutableListOf() }.add(intervals[i]) } } } return graph } private fun mergeNodes(nodes: List): IntArray { val minStart = nodes.minOf { it[0] } val maxEnd = nodes.maxOf { it[1] } return intArrayOf(minStart, maxEnd) } private fun getComponents( graph: HashMap • , MutableList>, intervals: Array ): Pair { val visited = mutableSetOf • >() var compNumber = 0 val nodesInComp = HashMap() fun markComponentDFS(start: IntArray) { val stack = mutableListOf(start) while (stack.isNotEmpty()) { val node = stack.removeLast().toList() if (node !in visited) { visited.add(node) nodesInComp.getOrPut(compNumber) { mutableListOf() }.add(start) graph[node]?.forEach { stack.add(it) } } } } for (interval in intervals) { if (interval.toList() !in visited) { markComponentDFS(interval) compNumber++ } } return Pair(nodesInComp, compNumber) } fun merge(intervals: Array): Array { val (graph, nodesInComp, numberComps) = buildGraph(intervals).let { val (nodesInComp, numberComps) = getComponents(it, intervals) Triple(it, nodesInComp, numberComps) } return Array(numberComps) { comp -> mergeNodes(nodesInComp[comp]!!) } } } Ставь 👍 и забирай 📚 Базу знаний
Kotlin | LeetCode
FAQ

Open Kotlin | LeetCode in Telegram and press the Start button. No separate registration is required.

Yes. The service is designed to be straightforward: open the resource, follow the on-screen instructions and start using it.

No. You can use Kotlin | LeetCode directly in Telegram unless the resource description says otherwise.

Access depends on the resource. Check the current information in Telegram after opening Kotlin | LeetCode.

The exact features depend on the resource. Open Kotlin | LeetCode to see its current functions, content and access conditions.

Reviews for channel Kotlin | LeetCode

Log in to leave a review

Only registered users can share their opinion.

No reviews yet

Be the first to share your impression of this resource!

Similar resources

Loading
Switch to Light Theme
Home Catalog Collections Blog Login