и посмотреть медиа
Kotlin LeetCode
и посмотреть медиа
Problemas y soluciones de LeetCode en Kotlin.
Problemas y soluciones de LeetCode en Kotlin.
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.
Soluciones de problemas de LeetCode en Kotlin. Código optimizado para desarrolladores móviles y especialistas en algoritmos.
Задача: 1065. Index Pairs of a String Сложность: easy Дана строка text и массив строк words, верните массив всех пар индексов [i, j], таких что подстрока text[i...j] находится в words. Верните пары [i, j] в отсортированном порядке (то есть отсортируйте их по первой координате, а в случае совпадения сортируйте их по второй координате). Пример: Input: text = "thestoryofleetcodeandme", words = ["story","fleet","leetcode"] Output: [[3,7],[9,13],[10,17]] 👨💻 Алгоритм: 1⃣Поддерживайте хэш-набор слов. 2⃣Итерируйте i от 0 до text.length-1. Итерируйте j от i до text.length-1. Если подстрока text[i...j] принадлежит хэш-набору слов, добавьте пару [i, j] в ответ. 3⃣Верните ответ. 😎 Решение: class Solution { fun indexPairs(text: String, words: Array): List • > { val wordsSet = words.toSet() val ans = mutableListOf • >() for (i in text.indices) { for (j in i until text.length) { if (text.substring(i, j + 1) in wordsSet) { ans.add(listOf(i, j)) } } } return ans } } Ставь 👍 и забирай 📚 Базу знаний
Открыть канал и посмотреть медиаSolo los usuarios registrados pueden compartir su opinión.
¡Sé el primero en compartir tu experiencia con este recurso!