Logo
TGCATALOG
Catálogo Selecciones Blog
Kotlin  LeetCode

Kotlin LeetCode

Problemas y soluciones de LeetCode en Kotlin.

Sin valoraciones
432
02.12.2026
432
02.12.2026
Sin valoraciones
432
02.12.2026
Redirección segura vía bot
О канале

Problemas y soluciones de LeetCode en Kotlin.

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

También te recomendamos

Kekaton AI  Voz en off y clon de voz
Kekaton AI Voz en off y clon de voz
Bot

bot de IA para clonar texto a voz y voz en Telegram. Cree audio utilizando la red neuronal de forma rápida y fácil.

Descripción

Soluciones de problemas de LeetCode en Kotlin. Código optimizado para desarrolladores móviles y especialistas en algoritmos.

Últimas publicaciones

Kotlin  LeetCode
Kotlin LeetCode
🔒Открыть пост
и посмотреть медиа
Задача: 1338. Reduce Array Size to The Half Сложность: medium Дан массив целых чисел arr. Вы можете выбрать набор чисел и удалить все вхождения этих чисел из массива. Верните минимальный размер набора, чтобы было удалено не менее половины целых чисел из массива. Пример: Input: arr = [3,3,3,3,5,5,5,2,2,7] Output: 2 Explanation: Choosing {3,7} will make the new array [5,5,5,2,2] which has size 5 (i.e equal to half of the size of the old array). Possible sets of size 2 are {3,5},{3,2},{5,2}. Choosing set {2,7} is not possible as it will make the new array [3,3,3,3,5,5,5] which has a size greater than half of the size of the old array. 👨💻 Алгоритм: 1⃣Отсортировать массив и создать список подсчета количества вхождений каждого числа. 2⃣Отсортировать список подсчета в порядке убывания. 3⃣Удалять числа из массива, начиная с наибольшего количества вхождений, пока не будет удалено не менее половины чисел массива. Вернуть размер множества удаленных чисел. 😎 Решение: class Solution { fun minSetSize(arr: IntArray): Int { arr.sort() val counts = mutableListOf() var currentRun = 1 for (i in 1 until arr.size) { if (arr[i] == arr[i - 1]) { currentRun += 1 continue } counts.add(currentRun) currentRun = 1 } counts.add(currentRun) counts.sortDescending() var numbersRemovedFromArr = 0 var setSize = 0 for (count in counts) { numbersRemovedFromArr += count setSize += 1 if (numbersRemovedFromArr >= arr.size / 2) { break } } return setSize } } Ставь 👍 и забирай 📚 Базу знаний
Kotlin LeetCode

Reseñas de canal Kotlin LeetCode

Inicia sesión para dejar una reseña

Solo los usuarios registrados pueden compartir su opinión.

Aún no hay reseñas

¡Sé el primero en compartir tu experiencia con este recurso!

Recursos similares

Loading
Cambiar a tema claro
Inicio Catálogo Selecciones Blog Entrar