Logo
TGCATALOG
Catalog Collections Blog
C# LeetCode - tasks

C# LeetCode - tasks

LeetCode C#.

No ratings
622
31.10.2026
622
31.10.2026
No ratings
622
31.10.2026
Safe redirect via bot
О канале

LeetCode C#.

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

Latest posts

C# LeetCode - tasks
C# LeetCode - tasks
🔒Открыть пост
и посмотреть медиа
Задача: 1101. The Earliest Moment When Everyone Become Friends Сложность: medium В социальной группе есть n человек, пронумерованных от 0 до n - 1. Вам дан массив logs, где logs[i] = [timestampi, xi, yi] указывает, что xi и yi станут друзьями в момент времени timestampi. Дружба является симметричной. Это означает, что если a является другом b, то b является другом a. Также человек a знаком с человеком b, если a является другом b или a является другом кого-то, кто знаком с b. Верните самое раннее время, когда каждый человек стал знаком с каждым другим человеком. Если такого времени не существует, верните -1. Пример: Input: logs = [[0,2,0],[1,0,1],[3,0,3],[4,1,2],[7,3,1]], n = 4 Output: 3 Explanation: At timestamp = 3, all the persons (i.e., 0, 1, 2, and 3) become friends. 👨💻 Алгоритм: 1⃣Отсортируйте логи по времени в хронологическом порядке, так как в задаче не указано, отсортированы ли они. 2⃣Пройдитесь по отсортированным логам, применяя структуру данных "Объединение-Поиск": Для каждого лога объедините двух участников, упомянутых в логе, с помощью функции union(a, b). Каждое объединение добавляет новые связи между участниками. 3⃣Следите за количеством групп: Изначально каждый участник рассматривается как отдельная группа. Количество групп уменьшается с каждым полезным объединением. Момент, когда количество групп уменьшается до одной, является самым ранним моментом, когда все участники становятся связанными (друзьями). Верните этот момент времени. Если такого момента не существует, верните -1. 😎 Решение: public class UnionFind { private int[] parent; private int[] rank; public UnionFind(int n) { parent = new int[n]; rank = new int[n]; for (int i = 0; i < n; i++) { parent[i] = i; rank[i] = 1; } } public int Find(int x) { if (parent[x] != x) { parent[x] = Find(parent[x]); } return parent[x]; } public bool Union(int x, int y) { int rootX = Find(x); int rootY = Find(y); if (rootX != rootY) { if (rank[rootX] > rank[rootY]) { parent[rootY] = rootX; } else if (rank[rootX] < rank[rootY]) { parent[rootX] = rootY; } else { parent[rootY] = rootX; rank[rootX]++; } return true; } return false; } } public class Solution { public int EarliestAcq(int[][] logs, int n) { Array.Sort(logs, (a, b) => a[0].CompareTo(b[0])); var uf = new UnionFind(n); int groupCount = n; foreach (var log in logs) { int timestamp = log[0]; int friendA = log[1]; int friendB = log[2]; if (uf.Union(friendA, friendB)) { groupCount--; } if (groupCount == 1) { return timestamp; } } return -1; } } Ставь 👍 и забирай 📚 Базу знаний
C# LeetCode - tasks
FAQ

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

Access depends on the resource. Check the current information in Telegram after opening C# LeetCode - tasks.

The exact features depend on the resource. Open C# LeetCode - tasks to see its current functions, content and access conditions.
Subscriber dynamics
+-1.0% last 30 days
Current
3,158
Month ago
3,190
Average growth
+-1 / day
Updated
5 hours ago

Reviews for channel C# LeetCode - tasks

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