и посмотреть медиа
Kotlin | LeetCode
и посмотреть медиа
LeetCode problems and solutions in Kotlin.
LeetCode problems and solutions in Kotlin.
AI bot for text-to-speech and voice cloning in Telegram. Create audio using neural network quickly and easily.
LeetCode problem solutions in Kotlin. Optimized code for mobile developers and algorithm specialists.
Задача: 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 } } Ставь 👍 и забирай 📚 Базу знаний
Открыть канал и посмотреть медиаOnly registered users can share their opinion.
Be the first to share your impression of this resource!