Logo
TGCATALOG
Catalog Collections Blog
Kotlin | LeetCode

Kotlin | LeetCode

LeetCode problems and solutions in Kotlin.

No ratings
432
02.12.2026
432
02.12.2026
No ratings
432
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
🔒Открыть пост
и посмотреть медиа
Задача: 827. Making A Large Island Сложность: hard Вам дан n x n бинарный матрица grid. Вам разрешено изменить не более одного 0 на 1. Верните размер самого большого острова в grid после выполнения этой операции. Остров — это группа 1, соединенных в 4 направлениях. Пример: Input: grid = [[1,1],[1,0]] Output: 4 Explanation: Change the 0 to 1 and make the island bigger, only one island with area = 4. 👨💻 Алгоритм: 1⃣Пройдите по матрице и пометьте каждую группу, используя уникальный индекс, и запомните её размер. 2⃣Для каждого 0 в матрице проверьте соседние группы и вычислите потенциальный размер острова, если изменить этот 0 на 1. 3⃣Возвращайте максимальный размер острова, учитывая как уже существующие острова, так и потенциальные, образованные после изменения 0 на 1. 😎 Решение: class Solution { private val directions = arrayOf( intArrayOf(-1, 0), intArrayOf(0, -1), intArrayOf(1, 0), intArrayOf(0, 1) ) private lateinit var grid: Array private var N = 0 fun largestIsland(grid: Array): Int { this.grid = grid N = grid.size var index = 2 val area = IntArray(N * N + 2) for (r in 0 until N) { for (c in 0 until N) { if (grid[r][c] == 1) { area[index] = dfs(r, c, index) index++ } } } var ans = area.maxOrNull() ?: 0 for (r in 0 until N) { for (c in 0 until N) { if (grid[r][c] == 0) { val seen = mutableSetOf() for ((nr, nc) in neighbors(r, c)) { if (grid[nr][nc] > 1) { seen.add(grid[nr][nc]) } } ans = maxOf(ans, 1 + seen.sumOf { area[it] }) } } } return ans } private fun dfs(r: Int, c: Int, index: Int): Int { var ans = 1 grid[r][c] = index for ((nr, nc) in neighbors(r, c)) { if (grid[nr][nc] == 1) { grid[nr][nc] = index ans += dfs(nr, nc, index) } } return ans } private fun neighbors(r: Int, c: Int): List { val result = mutableListOf() for (dir in directions) { val nr = r + dir[0] val nc = c + dir[1] if (nr in 0 until N && nc in 0 until N) { result.add(nr to nc) } } return result } Ставь 👍 и забирай 📚 Базу знаний
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