Logo
TGCATALOG
Catalog Collections Blog
Kotlin | LeetCode

Kotlin | LeetCode

LeetCode problems and solutions in Kotlin.

No ratings
430
01.12.2026
430
01.12.2026
No ratings
430
01.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
🔒Открыть пост
и посмотреть медиа
Задача: 711. Number of Distinct Islands II Сложность: hard Вам дана двоичная матричная сетка m x n. Остров - это группа 1 (представляющая сушу), соединенных в четырех направлениях (горизонтальном или вертикальном). Можно предположить, что все четыре края сетки окружены водой. Остров считается одинаковым с другим, если они имеют одинаковую форму, или имеют одинаковую форму после поворота (только на 90, 180 или 270 градусов) или отражения (влево/вправо или вверх/вниз). Верните количество разных островов. Пример: Input: grid = [[1,1,0,0,0],[1,0,0,0,0],[0,0,0,0,1],[0,0,0,1,1]] Output: 1 👨💻 Алгоритм: 1⃣Пройдите по каждому элементу матрицы, если найдена земля (1), выполните DFS для обнаружения всех связанных с этим островом земель и сохраните форму острова. 2⃣Нормализуйте форму острова, применив все возможные повороты и отражения, чтобы найти каноническую форму. 3⃣Используйте множество для хранения всех уникальных канонических форм и верните размер этого множества. 😎 Решение: class Solution { fun numDistinctIslands2(grid: Array): Int { val uniqueIslands = mutableSetOf() for (i in grid.indices) { for (j in grid[0].indices) { if (grid[i][j] == 1) { val shape = mutableListOf() dfs(grid, i, j, i, j, shape) uniqueIslands.add(normalize(shape)) } } } return uniqueIslands.size } private fun dfs(grid: Array, i: Int, j: Int, baseI: Int, baseJ: Int, shape: MutableList) { if (i < 0 || i >= grid.size || j < 0 || j >= grid[0].size || grid[i][j] == 0) { return } grid[i][j] = 0 shape.add(Pair(i - baseI, j - baseJ)) dfs(grid, i + 1, j, baseI, baseJ, shape) dfs(grid, i - 1, j, baseI, baseJ, shape) dfs(grid, i, j + 1, baseI, baseJ, shape) dfs(grid, i, j - 1, baseI, baseJ, shape) } private fun normalize(shape: List): String { val shapes = List(8) { mutableListOf() } for ((x, y) in shape) { shapes[0].add(Pair(x, y)) shapes[1].add(Pair(x, -y)) shapes[2].add(Pair(-x, y)) shapes[3].add(Pair(-x, -y)) shapes[4].add(Pair(y, x)) shapes[5].add(Pair(y, -x)) shapes[6].add(Pair(-y, x)) shapes[7].add(Pair(-y, -x)) } for (s in shapes) { s.sortWith(compareBy({ it.first }, { it.second })) } val minShape = shapes.minByOrNull { it.toString() }!! return minShape.joinToString(";") { "${it.first},${it.second}" } } } Ставь 👍 и забирай 📚 Базу знаний
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