Logo
TGCATALOG
Catalog Collections Blog
C/C++ LeetCode - задачи

C/C++ LeetCode - задачи

LeetCode задачи C/C++.

No ratings
54
10.09.2026
54
10.09.2026
No ratings
54
10.09.2026
Safe redirect via bot
О канале

LeetCode задачи C/C++.

Подписчиков 3,234
Тематика Technology
Язык English
Ссылка t.me/easy_c_plus_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

Решения и задачи LeetCode на C/C++.

Latest posts

C/C++ LeetCode - задачи
C/C++ LeetCode - задачи
🔒Открыть пост
и посмотреть медиа
Задача: 210. Course Schedule II Сложность: medium Дано число numCourses и список пар prerequisites, где каждая пара [a, b] означает: чтобы взять курс a, нужно сначала пройти курс b. Верните один из возможных порядков прохождения курсов. Если пройти все курсы невозможно (из-за циклов) — верните пустой массив. Пример: Input: numCourses = 4, prerequisites = [[1,0],[2,0],[3,1],[3,2]] Output: [0,2,1,3] 👨💻 Алгоритм: 1⃣Построение графа и подготовка к DFS Создаем список смежности adjList, где adjList[b] содержит все курсы, зависящие от b. Каждый курс помечаем цветом: WHITE = 1 — не посещён GRAY = 2 — в процессе обработки BLACK = 3 — полностью обработан 2⃣Обход в глубину (DFS) и детектирование цикла Для каждого непосещённого узла запускаем dfs. Если во время обхода обнаруживаем цикл (возврат к GRAY узлу), значит, пройти курсы невозможно. 3⃣Формирование ответа После завершения DFS по всем узлам формируем порядок курсов из стека (или массива) topologicalOrder, инвертируя его. 😎Решение: cppКопироватьРедактироватьclass Solution { public: int WHITE = 1; int GRAY = 2; int BLACK = 3; vector findOrder(int numCourses, vector& prerequisites) { bool isPossible = true; map color; map adjList; vector topologicalOrder; for (int i = 0; i < numCourses; i++) color[i] = WHITE; for (vector relation : prerequisites) { int dest = relation[0]; int src = relation[1]; adjList[src].push_back(dest); } for (int i = 0; i < numCourses && isPossible; i++) { if (color[i] == WHITE) { dfs(i, color, adjList, isPossible, topologicalOrder); } } vector order; if (isPossible) { order.resize(numCourses); for (int i = 0; i < numCourses; i++) { order[i] = topologicalOrder[numCourses - i - 1]; } } return order; } void dfs(int node, map& color, map& adjList, bool& isPossible, vector& topologicalOrder) { if (!isPossible) return; color[node] = GRAY; for (int neighbor : adjList[node]) { if (color[neighbor] == WHITE) { dfs(neighbor, color, adjList, isPossible, topologicalOrder); } else if (color[neighbor] == GRAY) { isPossible = false; } } color[node] = BLACK; topologicalOrder.push_back(node); } }; Ставь 👍 и забирай 📚 Базу знаний
C/C++ LeetCode - задачи
Subscriber dynamics
+0.0% last 30 days
Current
3,234
Month ago
3,234
Average growth
+0 / day
Updated
11 hours ago

Reviews for channel C/C++ 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

BJ Corporate Centre:S-UNITcompanies,facilitiesand partner projects in Telegram.

Channel

BinanceRed Packet: crypto boxes,giveawayAnd free crypt distributions. Daily opportunities for awards.

Channel
32

Moto community and content about motorcycles.

Channel
Switch to Light Theme
Home Catalog Collections Blog Login