Logo
TGCATALOG
Catalog Collections Blog
Golang | LeetCode

Golang | LeetCode

LeetCode tasks in Golang. Solutions with code and explanations.

No ratings
375
02.12.2026
375
02.12.2026
No ratings
375
02.12.2026
Safe redirect via bot
О канале

LeetCode tasks in Golang. Solutions with code and explanations.

Подписчиков —
Тематика Technology
Ссылка @easy_golang_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

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.

Latest posts

Golang | LeetCode
Golang | LeetCode
🔒Открыть пост
и посмотреть медиа
Задача: 672. Bulb Switcher II Сложность: medium Дано количество лампочек n (все включены) и количество нажатий presses. Есть 4 кнопки с разной логикой. Нужно определить, сколько различных состояний лампочек может быть получено после ровно presses нажатий. Пример: Input: n = 1, presses = 1` → Output: 2 👨💻 Алгоритм: 1⃣Ограничиваем количество лампочек до 6 Поскольку шаблоны переключений кнопок начинают повторяться при n > 6, достаточно проверять только первые min(n, 6) лампочек. Остальные комбинации будут симметричны и не дадут новых состояний. 2⃣Перебираем все возможные комбинации нажатий кнопок Каждая из 4 кнопок может быть либо нажата, либо нет — всего 2⁴ = 16 комбинаций. Проверяем каждую комбинацию cand, у которой: - Кол-во нажатых кнопок bcount ≤ presses - Чётность bcount % 2 == presses % 2 (так как порядок не важен) 3⃣Симулируем состояние лампочек и собираем уникальные Для каждой валидной комбинации симулируем, какие лампочки будут переключены (с помощью битовых масок и XOR). Сохраняем результат в map, чтобы получить множество уникальных состояний. Возвращаем размер множества. 😎 Решение: import ( "math/bits" ) func flipLights(n int, m int) int { seen := make(map[int]struct{}) n = min(n, 6) shift := max(0, 6-n) for cand := 0; cand < 16; cand++ { bcount := bits.OnesCount(uint(cand)) if bcount % 2 == m % 2 && bcount >0)&1 > 0 { lights ^= 0b111111 >> shift } if (cand>>1)&1 > 0 { lights ^= 0b010101 >> shift } if (cand>>2)&1 > 0 { lights ^= 0b101010 >> shift } if (cand>>3)&1 > 0 { lights ^= 0b100100 >> shift } seen[lights] = struct{}{} } } return len(seen) } func min(a, b int) int { if a < b { return a } return b } func max(a, b int) int { if a > b { return a } return b } Ставь 👍 и забирай 📚 Базу знаний
Golang | LeetCode
FAQ

Open Golang | 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 Golang | LeetCode directly in Telegram unless the resource description says otherwise.

Access depends on the resource. Check the current information in Telegram after opening Golang | LeetCode.

The exact features depend on the resource. Open Golang | LeetCode to see its current functions, content and access conditions.

Reviews for channel Golang | 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