и посмотреть медиа
Golang | LeetCode
и посмотреть медиа
LeetCode tasks in Golang. Solutions with code and explanations.
LeetCode tasks in Golang. Solutions with code and explanations.
AI bot for text-to-speech and voice cloning in Telegram. Create audio using neural network quickly and easily.
Channel with solutions to popular LeetCode tasks in Go. Focus on optimized algorithms, efficient memory usage, and idiomatic code. Helps prepare for technical interviews in companies that use Golang.
Задача: №28. Find the Index of the First Occurrence in a String Сложность: easy Учитывая две строки, needle и haystack, верните индекс первого вхождения needle в haystack, или -1, если needle не является частью haystack. Пример: Input: haystack = "sadbutsad", needle = "sad" Output: 0 👨💻 Алгоритм: 1⃣Обработка граничного случая: - Если needle — пустая строка, вернуть 0 (по определению). 2⃣Итерация по возможным позициям: - Проходим по всем индексам i от 0 до len(haystack) - len(needle), - На каждой итерации сравниваем срез haystack[i:i+len(needle)] с needle. 3⃣Проверка совпадений: - Если подстроки совпали — возвращаем текущий индекс i. - Если не нашли ни одного совпадения — возвращаем -1. 😎 Решение: func strStr(haystack string, needle string) int { n := len(needle) if n == 0 { return 0 } for i := 0; i
Открыть канал и посмотреть медиаOnly registered users can share their opinion.
Be the first to share your impression of this resource!