Logo
TGCATALOG
Catalog Collections Blog
Golang | LeetCode

Golang | LeetCode

LeetCode tasks in Golang. Solutions with code and explanations.

No ratings
376
02.12.2026
376
02.12.2026
No ratings
376
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
🔒Открыть пост
и посмотреть медиа
Задача: 1001. Grid Illumination Сложность: hard Имеется двумерная сетка размером n x n, в каждой ячейке которой есть лампа, изначально выключенная. Вам дан двумерный массив позиций ламп lamps, где lamps[i] = [rowi, coli] означает, что лампа в ячейке grid[rowi][coli] включена. Даже если одна и та же лампа указана несколько раз, она включена. Когда лампа включена, она освещает свою ячейку и все остальные ячейки в той же строке, столбце или диагонали. Вам также дан другой двумерный массив queries, где queries[j] = [rowj, colj]. Для j-го запроса определите, освещена ли сетка[rowj][colj] или нет. После ответа на j-й запрос выключите лампу в сетке[rowj][colj] и 8 соседних ламп, если они существуют. Лампа является смежной, если ее ячейка имеет общую сторону или угол с сеткой[rowj][colj]. Верните массив целых чисел ans, где ans[j] должно быть 1, если ячейка в j-м запросе была освещена, или 0, если лампа не была освещена. Пример: Input: n = 5, lamps = [[0,0],[4,4]], queries = [[1,1],[1,0]] Output: [1,0] 👨💻 Алгоритм: 1⃣Инициализация данных: Используйте множества для хранения включенных ламп, освещенных строк, столбцов, диагоналей и обратных диагоналей. Инициализируйте множества и словари для отслеживания количества ламп, освещающих каждую строку, столбец, диагональ и обратную диагональ. 2⃣Обработка запросов: Для каждого запроса проверьте, освещена ли ячейка, используя словари строк, столбцов, диагоналей и обратных диагоналей. После ответа на запрос выключите лампу в указанной ячейке и 8 соседних ячейках, обновив множества и словари. 3⃣Обновление состояний ламп: Обновите состояния ламп и освещенных ячеек после каждого запроса, чтобы корректно обрабатывать следующие запросы. 😎 Решение: func gridIllumination(n int, lamps [][]int, queries [][]int) []int { lamps_on := make(map[[2]int]bool) rows := make(map[int]int) cols := make(map[int]int) diag1 := make(map[int]int) diag2 := make(map[int]int) for _, lamp := range lamps { r, c := lamp[0], lamp[1] key := [2]int{r, c} if lamps_on[key] { continue } lamps_on[key] = true rows[r]++ cols[c]++ diag1[r-c]++ diag2[r+c]++ } directions := [][2]int{{0, 0}, {0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1}} result := make([]int, len(queries)) for i, query := range queries { r, c := query[0], query[1] if rows[r] > 0 || cols[c] > 0 || diag1[r-c] > 0 || diag2[r+c] > 0 { result[i] = 1 } else { result[i] = 0 } for _, dir := range directions { nr, nc := r+dir[0], c+dir[1] key := [2]int{nr, nc} if lamps_on[key] { delete(lamps_on, key) rows[nr]-- cols[nc]-- diag1[nr-nc]-- diag2[nr+nc]-- } } } return result } Ставь 👍 и забирай 📚 Базу знаний
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